In this chapter, we will explain you how to sort records in MongoDB.
Sort() method is used to sort documents in MongoDB. This method will accept a document which consists of a list of fields including their sorting order. 1 and -1 are used for specifying the sorting order. 1 is used for ascending order and -1 is used for descending order.
Basic syntax of sort() method is as follows
Consider collection mycol has below data.
Below example displays the documents sorted by title in the descending order.
Remember that if you don't specify the sorting preference, then sort() method will display the documents in ascending order.
MongoDB Related Interview Questions
|Python Interview Questions||C & Data Structures Interview Questions|
|Hadoop Interview Questions||Node.js Interview Questions|
|Scala Interview Questions||Socket Programming Interview Questions|
|HBase Interview Questions||Solaris Administrator Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.