0
0
MongoDBquery~10 mins

Sorting by multiple fields 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 documents by the field 'age' in ascending order.

MongoDB
db.collection.find().sort([1]: 1})
Drag options to blanks, or click blank then click option'
Ascore
Bdate
Cname
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 instead of 1 for ascending order.
Putting the field name outside the braces.
2fill in blank
medium

Complete the code to sort documents by 'score' in descending order.

MongoDB
db.collection.find().sort([1]: -1})
Drag options to blanks, or click blank then click option'
Ascore
Bage
Cname
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of -1 for descending order.
Selecting the wrong field name.
3fill in blank
hard

Fix the error in the code to sort by 'name' ascending and then by 'age' descending.

MongoDB
db.collection.find().sort({name: 1, [1]: -1})
Drag options to blanks, or click blank then click option'
Aheight
Bage
Cdate
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using a field not in the collection.
Using 1 instead of -1 for descending order.
4fill in blank
hard

Fill both blanks to sort by 'score' descending and then by 'date' ascending.

MongoDB
db.collection.find().sort([1]: -1, [2]: 1})
Drag options to blanks, or click blank then click option'
Ascore
Bage
Cdate
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of fields.
Using wrong sort directions.
5fill in blank
hard

Fill all three blanks to sort by 'name' ascending, then 'score' descending, then 'age' ascending.

MongoDB
db.collection.find().sort([1]: 1, [2]: -1, [3]: 1})
Drag options to blanks, or click blank then click option'
Aname
Bscore
Cage
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of fields.
Using wrong sort directions for fields.