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…
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
Options
- A3
- B5
- C4
- D2
- E1
How the community answered
(50 responses)- A2% (1)
- B72% (36)
- C14% (7)
- D4% (2)
- E8% (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
$unwindexpands 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'
traitsarrays, ignoring the contribution of the other. - E (1) has no basis -
$unwindnever 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
Community Discussion
No community discussion yet for this question.
