MongoDB - Sorting
In any application we need to show list in certain order. Generally we show's user feeds in descending order. This can be achieve in MongoDB through "sort" properties.
e.g. We need to sort student name in ascending order.
db.collection.find().sort({ columnname : 1})
1 belongs to ascending order.
-1 belongs to descending order.
In above query if we want to show student name in desecending order then query should be:
db.collection.find().sort({columnname: -1 })
We can sort multiple column with the following query.
db.collection.find().sort({columnname1: -1 , columnname2: 1 })
0 Comment(s)