Python Tutorials · Python MongoDB
MongoDB Sort
Learn all about MongoDB Sort in this comprehensive tutorial.
5 min read advanced
- •Use the sort() method to sort the result in ascending or descending order.
- •Use the value -1 as the second parameter to sort descending.
Sort the Result
Use the sort() method to sort the result in ascending or descending order.
The sort() method takes one parameter for "fieldname" and one parameter for "direction" (ascending is the default direction).
python
Sort Descending
Use the value -1 as the second parameter to sort descending.
Note: sort("name", 1) #ascending
sort("name", -1) #descending
python
Module quiz
2 questions1
Which of the following is true about MongoDB Sort?
2
What is the most common pitfall when working with MongoDB Sort?
Answer all questions to submit.