Recall & Review
beginner
What is the purpose of the
$group stage in MongoDB aggregation?The
$group stage groups documents by a specified key and allows you to perform calculations like sums, averages, or counts on each group.Click to reveal answer
beginner
In the
$group stage, what does the _id field represent?The
_id field defines the key to group documents by. Each unique value of _id creates a separate group.Click to reveal answer
beginner
How do you count the number of documents in each group using
$group?Use
{ $sum: 1 } inside the $group stage to add 1 for each document, effectively counting them.Click to reveal answer
intermediate
What aggregation operators can be used inside
$group to calculate totals or averages?You can use
$sum to add values, $avg to calculate averages, $max for maximum, and $min for minimum values.Click to reveal answer
intermediate
Can
$group stage change the shape of documents?Yes,
$group outputs one document per group with fields you define, so the shape can be very different from the original documents.Click to reveal answer
What does the
_id field in $group specify?✗ Incorrect
The
_id field in $group defines the key used to group documents.Which operator counts documents in each group?
✗ Incorrect
Using
{ $sum: 1 } adds 1 for each document, counting them.Which operator calculates the average value in
$group?✗ Incorrect
$avg calculates the average of numeric values in each group.Can
$group stage output documents with different fields than the input?✗ Incorrect
$group outputs one document per group with fields you define, changing the shape.Which of these is NOT a valid accumulator operator in
$group?✗ Incorrect
$concat is a string operator, not an accumulator used in $group.Explain how the
$group stage works in MongoDB aggregation.Think about how you would group items in real life, like grouping fruits by type and counting them.
You got /3 concepts.
Describe how to count the number of documents in each group using
$group.Counting is like adding one for each item in the group.
You got /2 concepts.