Recall & Review
beginner
What does the
$min accumulator do in MongoDB aggregation?The
$min accumulator finds the smallest value for a specified field across grouped documents.Click to reveal answer
beginner
What is the purpose of the
$max accumulator in MongoDB?The
$max accumulator returns the largest value for a specified field from grouped documents.Click to reveal answer
intermediate
How do
$min and $max behave when used in a $group stage?They compute the minimum and maximum values respectively for each group of documents defined by the
_id field in the $group stage.Click to reveal answer
intermediate
Can
$min and $max be used on fields with different data types?They work best on comparable data types like numbers or dates. Mixing incompatible types can lead to unexpected results or errors.
Click to reveal answer
beginner
Example: How to find the minimum and maximum price of products in each category using MongoDB aggregation?
Use
$group with _id as category, and $min: "$price" and $max: "$price" to get min and max prices per category.Click to reveal answer
What does the
$min accumulator return in a MongoDB aggregation?✗ Incorrect
$min finds the smallest value for a specified field within each group.
Which accumulator would you use to find the highest score in a group of documents?
✗ Incorrect
$max returns the largest value in the group.
In which aggregation stage are
$min and $max typically used?✗ Incorrect
$min and $max are used in $group to aggregate values per group.
What happens if you use
$min on a field with mixed data types?✗ Incorrect
Using $min on mixed types can cause errors or unexpected results because values are not comparable.
How do you specify the field to find the minimum value of in
$min?✗ Incorrect
You specify the field with a $ prefix, for example "$price".
Explain how
$min and $max accumulators work in MongoDB aggregation.Think about grouping documents and finding extreme values.
You got /4 concepts.
Describe a real-life example where you would use
$min and $max in a database query.Consider a store with products or a class with student scores.
You got /4 concepts.