Complete the code to sort documents by the field 'age' in ascending order.
db.collection.find().sort([1]: 1})
The sort method sorts documents by the specified field. Here, sorting by age ascending uses {age: 1}.
Complete the code to sort documents by 'score' in descending order.
db.collection.find().sort([1]: -1})
Sorting by score descending uses {score: -1}.
Fix the error in the code to sort by 'name' ascending and then by 'age' descending.
db.collection.find().sort({name: 1, [1]: -1})To sort by multiple fields, list them in order. Here, after name, use age descending.
Fill both blanks to sort by 'score' descending and then by 'date' ascending.
db.collection.find().sort([1]: -1, [2]: 1})
The first field is score descending (-1), then date ascending (1).
Fill all three blanks to sort by 'name' ascending, then 'score' descending, then 'age' ascending.
db.collection.find().sort([1]: 1, [2]: -1, [3]: 1})
Sort first by name ascending, then score descending, then age ascending.