0
0
MongoDBquery~10 mins

sort method ascending and descending in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A0
B-1
C1
Dasc
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.
2fill in blank
medium

Complete 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'
A-1
B0
C1
Ddesc
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.
3fill in blank
hard

Fix 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'
A'asc'
B'ascending'
Ctrue
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of numbers for sort order.
Using boolean values which are invalid.
4fill in blank
hard

Fill 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'
A1
B-1
C0
Dasc
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which does not sort.
Using strings like 'asc' or 'desc' which are invalid.
5fill in blank
hard

Fill 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'
A1
B-1
C0
Dasc
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which does not sort.
Using strings instead of numbers for sort order.