C100DEV Aggregation Framework Practice Question
When using the $lookup stage, what happens if the 'foreignField' contains values that are not present in the 'localField' of the joined collection?
⚠ Common exam trap
Candidates often assume that an unmatched $lookup will drop the parent document entirely, confusing it with an inner join rather than recognizing its left outer join behavior.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The result field contains an empty array for those documents.
The $lookup operator acts as a left outer join. If there is no match in the foreign collection for a given document, the resulting array field will simply be empty. This behavior is standard for left outer joins, ensuring that no source documents are dropped from the result set simply because they lack a corresponding record in the joined collection, preserving the integrity of the primary dataset.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The entire document is dropped from the pipeline result.
Why it's wrong here
$lookup does not drop documents. It performs a left outer join, which implies that even if no matching foreign documents are found, the primary document is preserved. The resulting field specified in the 'as' option will simply contain an empty array, indicating a lack of matching references.
- ✗
The database throws an error and the aggregation fails.
Why it's wrong here
MongoDB handles missing matches gracefully during a $lookup operation. It does not consider a lack of foreign records to be a failure state. The query will execute successfully, and the result will contain the original document with an empty array for the joined field.
- ✓
The result field contains an empty array for those documents.
Why this is correct
$lookup functions as a left outer join. When the foreign side of the join has no matching documents for a specific input, the field specified in the 'as' parameter is populated with an empty array. This allows developers to handle 'missing' data programmatically without losing the primary record.
- ✗
The result field is set to null.
Why it's wrong here
The output of a $lookup is always an array, regardless of whether a match is found or not. By design, if no matches exist, the field is initialized as an empty array [] rather than a null value, maintaining consistent data types for the application consuming the pipeline output.
About these practice questions
This C100DEV question is part of Courseiva's 259-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official MongoDB exam blueprint
This C100DEV practice question is part of Courseiva's free MongoDB certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the C100DEV exam.