Articles → MONGODB → Sort The Cursor Result In MongodbSort The Cursor Result In MongodbIn this article, we will sort the cursor result in MongoDB.Example Consider the following collection: -To sort the cursor result, we will use the following syntax: -var sortCursor1 = db.Articles.find() sortCursor1.sort({ subject: 1 })In the above code, we are sorting the Articles collection in an ascending order. Here 1 represents the ascending order and -1 represents the descending order.Output Posted By - Karan Gupta Posted On - Friday, March 15, 2024 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
var sortCursor1 = db.Articles.find() sortCursor1.sort({ subject: 1 })
Query/Feedback