MongoDB Tutorial - MongoDB Sort Documents

To sort documents in MongoDB, use sort() method. sort() method accepts a document containing list of fields along with their sorting order. 1 is used for ascending order while -1 is used for descending order.


The basic syntax of sort() method is as follows



The following example will display the documents sorted by title in descending order.


The default sorting order for sort() method is ascending order.