MongoDB - Sort Records

MongoDB - Sort Records the way to kind facts in MongoDB.

The type() Method

To sort files in MongoDB, you want to apply kind() approach. The technique accepts a file containing a list of fields in conjunction with their sorting order. Specify sorting order 1 and -1 are used.1 is used for ascending order even as -1 is used for descending order.


The primary syntax of kind() approach is as follows >db.COLLECTION_NAME.discover().kind(KEY:1)


Consider the collection myycol has the subsequent facts.

          "_id" : ObjectId(VV^euD3afPL^5), "identify":"MongoDB Overview"
 "_id" : ObjectId(VV^euD3afPL^6), "name":"NoSQL Overview"
 "_id" : ObjectId(VV^euD3afPL^7), "name":" Welookups"

Following example will display the files sorted by way of identify within the descending order.
"title":"NoSQL Overview"
"name":"MongoDB Overview"

Welookups is optimized for learning.Copy right 2018 - 2019 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.