Courseiva
Aggregation Framework →hardMultiple Choice

C100DEV Aggregation Framework Practice Question

Exhibit

db.sales.aggregate([
  { $match: { status: "A" } },
  { $lookup: { 
      from: "items", 
      localField: "item_id", 
      foreignField: "_id", 
      as: "details" 
  } },
  { $unwind: "$details" }
])

Refer to the exhibit. What is the effect of the $unwind stage on the aggregation pipeline?

⚠ Common exam trap

Test-takers frequently confuse $unwind with $lookup, or forget that $unwind completely drops documents where the target array is empty unless preserveNullAndEmptyArrays is explicitly enabled.

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

✓

It flattens the 'details' array, creating one output document per array element.

The $unwind stage deconstructs an array field from the input documents to output a document for each element. By using it after $lookup, it transforms an array of joined data into individual flat documents. This is a critical step when you want to group or sort by fields located inside the joined data, as those operations are much easier to perform on flat documents than on nested array structures.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    It removes the 'details' field entirely from the resulting documents.

    Why it's wrong here

    $unwind does not remove fields; rather, it expands them. It takes the array stored in the 'details' field and creates a new, separate document for every single element found inside that array, effectively flattening the structure so each record contains a single item instead of an array.

  • ✓

    It flattens the 'details' array, creating one output document per array element.

    Why this is correct

    The $unwind stage processes array fields by creating a copy of the input document for each element in the specified array. This flattens the nested data, allowing subsequent stages in the pipeline to access individual elements directly as if they were top-level fields of the document.

  • ✗

    It merges all elements of the 'details' array into a single string.

    Why it's wrong here

    $unwind does not perform string concatenation or merging of array elements. Its sole purpose is the deconstruction of arrays into multiple separate document instances. Attempting to use it for data conversion or formatting would result in unexpected structural changes rather than the desired string output.

  • ✗

    It sorts the 'details' array in ascending order.

    Why it's wrong here

    $unwind does not perform any sorting operations on the array elements. To sort an array, you would need to use a separate $sort stage or utilize the $sortArray operator within a $project stage before reaching the $unwind stage to ensure the output documents follow a specific order.

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 →

How Courseiva writes practice questions · Editorial policy

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.