Articles → MONGODB → Sort The Cursor Result In MongodbSort The Cursor Result In MongodbThis article explains how to sort cursor results 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 code above, we are sorting the Articles collection in ascending order. Here, 1 represents ascending order and -1 represents 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