Sorting Results Sets
An important aspect of retrieving documents from a MongoDB database is the ability to get it in a sorted format. This is especially helpful if you are only retrieving a certain number such as the top 10 or if you are paging the requests. The options object provides the
sort option that allows you to specify the sort order and direction of one or more fields in the document.
To sort option is specified using an array of
[field,<sort_order>] pairs where
sort_order is 1 for ascending and -1 for descending. For example to sort on the
name field descending first and then the
value field ascending you would use:...
Share this highlighthttp://www.safaribooksonline.com/a/nodejs-mongodb-and/54543/