Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the minimum value of the "score" field in the collection.
MongoDB
db.scores.aggregate([{ $group: { _id: null, minScore: { [1]: "$score" } } }]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $max instead of $min will return the maximum value.
Using $sum or $avg will return sums or averages, not minimum values.
✗ Incorrect
The $min accumulator finds the minimum value of the specified field in the documents.
2fill in blank
mediumComplete the code to find the maximum value of the "age" field in the collection.
MongoDB
db.users.aggregate([{ $group: { _id: null, maxAge: { [1]: "$age" } } }]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $min will return the smallest value instead of the largest.
Using $sum or $avg will not return the maximum value.
✗ Incorrect
The $max accumulator returns the highest value of the specified field.
3fill in blank
hardFix the error in the code to correctly find the minimum "price" in the collection.
MongoDB
db.products.aggregate([{ $group: { _id: null, minPrice: { [1]: "$price" } } }]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ before the field name causes the query to fail.
Using $max instead of $min returns the maximum, not minimum.
✗ Incorrect
The field name must be prefixed with a dollar sign to refer to the field value. Also, $min is the correct accumulator for minimum.
4fill in blank
hardFill both blanks to find the maximum "rating" and minimum "price" in the collection.
MongoDB
db.items.aggregate([{ $group: { _id: null, maxRating: { [1]: "$rating" }, minPrice: { [2]: "$price" } } }]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping $min and $max will give wrong results.
Using $sum or $avg will not find min or max values.
✗ Incorrect
Use $max to find the maximum rating and $min to find the minimum price.
5fill in blank
hardFill all three blanks to find the maximum "score", minimum "time", and average "age" in the collection.
MongoDB
db.records.aggregate([{ $group: { _id: null, maxScore: { [1]: "$score" }, minTime: { [2]: "$time" }, avgAge: { [3]: "$age" } } }]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up $min and $max accumulators.
Using $sum instead of $avg for average calculation.
✗ Incorrect
Use $max for maximum score, $min for minimum time, and $avg for average age.