Sorting on Multiple fields mongo DB

前端 未结 3 437
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 15:50

I have a query in mongo such that I want to give preference to the first field and then the second field.

Say I have to query such that

db.col.find({         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 16:36

    try this code it will sort data first based on name then keeping the 'name' in key holder it will sort 'filter'

     var cursor = db.collection('vc').find({   "name" :   { $in: [ /cpu/, /memo/ ]   }     }, { _id: 0, }).sort( { "name":1  ,  "filter": 1 } );
    

提交回复
热议问题