nerdexam
MongoDB

C100DBA · Question #127

Suposse tou have the following collection with only 2 documents: If you run an aggregation query and use { $unwind: "$traits" } as the first stage, how many documents will be passed to the next…

The correct answer is B. 5. $unwind deconstructs an array field by outputting one document per array element - so the total output depends on the combined number of elements across all traits arrays in the collection. With the two documents shown, the traits arrays contain a combined total of 5 elements…

MongoDB Fundamentals

Question

Suposse tou have the following collection with only 2 documents:

If you run an aggregation query and use { $unwind: "$traits" } as the first stage, how many documents will be passed to the next stage of the aggregation pipeline?

Exhibit

C100DBA question #127 exhibit

Options

  • A3
  • B5
  • C4
  • D2
  • E1

How the community answered

(50 responses)
  • A
    2% (1)
  • B
    72% (36)
  • C
    14% (7)
  • D
    4% (2)
  • E
    8% (4)

Explanation

$unwind deconstructs an array field by outputting one document per array element - so the total output depends on the combined number of elements across all traits arrays in the collection. With the two documents shown, the traits arrays contain a combined total of 5 elements, which is why 5 documents are passed to the next stage.

Why the distractors are wrong:

  • D (2) is the most tempting trap - it's the original document count, but $unwind expands documents, it does not preserve the original count.
  • C (4) and A (3) likely match the element count of just one of the two documents' traits arrays, ignoring the contribution of the other.
  • E (1) has no basis - $unwind never collapses documents.

Memory tip: Think of $unwind as a zipper being pulled apart - each tooth in the array becomes its own document. Count all array elements across all documents to get the output count, not the number of documents.

Topics

#aggregation pipeline#$unwind#array unwinding#document count

Community Discussion

No community discussion yet for this question.

Full C100DBA Practice