MongoDB之排序

在MongoDB中使用sort()方法对数据进行排序,sort()方法可以通过参数指定排序的字段,并使用1和-1来指定排序的方式,其中1为升序排列,而-1是用于降序排列。

语法:

>db.COLLECTION_NAME.find().sort({KEY:1})

例如:

>db.test.find({},{"title":1,_id:0}).sort({"likes":-1})
原文地址:https://www.cnblogs.com/lavender1221/p/13150618.html