// Descending sort db.shoes.aggregate( [ { $sort: { sizes: -1 } } ] ) 前两个查询均首先返回包含 _id: 'A' 的文档,因为 7 和11 分别是 sizes 数组中条目中的最小值和最大值。 按数组字段进行过滤器和排序 当您对包含数组的字段进行筛选和排序时,过滤器不会影响用作排序键的值。排序总是将所...
The following operation sorts the documents first by theagefield in descending order and then by thepostsfield in ascending order: db.users.find({}).sort({age:-1,posts:1} ) When comparing values of differentBSON typesin sort operations, MongoDB uses the following comparison order, from lowes...
Following example will display the documents sorted by title in the descending order.>db.mycol.find({},{"title":1,_id:0}).sort({"title":-1}) {"title":"Tutorials Point Overview"} {"title":"NoSQL Overview"} {"title":"MongoDB Overview"} > ...
Unless you specify the sort() method or use the $near operator, MongoDB does not guarantee the order of query results. Ascending/Descending Sort Specify in the sort parameter the field or fields to sort by and a value of 1 or -1 to specify an ascending or descending sort respectively. ...
A value of-1next to a field name specifies descending order. Here we sort the results by name in descending order: xxxxxxxxxx db.musicians.find( ).sort( {name:-1} ) Result: { "_id" : 8, "name" : "Stuart Chatwood", "instrument" : "Bass", "born" : 1969 } ...
sort("name", -1) #descending Example Sort the result reverse alphabetically by name: importpymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["mydatabase"] mycol = mydb["customers"] mydoc = mycol.find().sort("name", -1) ...
1 indicates the ascending order and -1 indicates descending order. The following pipeline contains three stages to sort the groupped documents. Example: Sort Groupped Data Copy db.employees.aggregate([ { $match:{ gender:'male'}}, { $group:{ _id:{ deptName:'$department.name'}, total...
MongoDB Node.jsMongoDBSort Sort the Result Use thesort()method to sort the result in ascending or descending order. Thesort()method takes one parameter, an object defining the sorting order. ExampleGet your own Node.js Server Sort the result alphabetically by name:...
document: A document that defines the sort order in{field: 1, field:-1,...}format where 1 is for ascending order and -1 is for descending order. The following inserts documents in theemployeescollection. Sample Data Copy db.employees.insertMany([ ...
dataField。这是该列的数据字段,属于字符串类型。 sortOrder。它是所述的排序顺序,类型为字符串。排序顺序的值可以是asc,desc,或null。链接的文件:从给出的链接中下载jQWidgets。在HTML文件中,找到下载文件夹中的脚本文件。