Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the documents by age in ascending order.
MongoDB
db.collection.find().sort({ age: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 instead of 1 for ascending order.
Using 0 which does not sort.
Using 'asc' which is not valid in MongoDB.
✗ Incorrect
In MongoDB, sorting in ascending order is done by using 1 as the value for the field in the sort method.
2fill in blank
mediumComplete the code to sort the documents by score in descending order.
MongoDB
db.collection.find().sort({ score: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of -1 for descending order.
Using 0 which does not sort.
Using 'desc' which is not valid in MongoDB.
✗ Incorrect
Descending order in MongoDB sort is indicated by -1 for the field.
3fill in blank
hardFix the error in the code to sort by name in ascending order.
MongoDB
db.collection.find().sort({ name: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of numbers for sort order.
Using boolean values which are invalid.
✗ Incorrect
The sort method requires 1 for ascending order, not strings or booleans.
4fill in blank
hardFill both blanks to sort by age ascending and score descending.
MongoDB
db.collection.find().sort({ age: [1], score: [2] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which does not sort.
Using strings like 'asc' or 'desc' which are invalid.
✗ Incorrect
Use 1 for ascending and -1 for descending in MongoDB sort method.
5fill in blank
hardFill all three blanks to sort by name descending, age ascending, and score descending.
MongoDB
db.collection.find().sort({ name: [1], age: [2], score: [3] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which does not sort.
Using strings instead of numbers for sort order.
✗ Incorrect
Descending order is -1, ascending is 1. Use these values for each field in the sort method.