嵌套数组按字段Mnogoose Node.js排序

时间:2019-01-22 06:27:02

标签: javascript node.js mongoose

嗨,我想按一个字段对嵌套数组进行排序。我的架构和排序代码如下所示:

const MainSchema=new Schema({
   name: {type: String},
   locations:[{
       locid: {type: Number},
       locname: {type: String}
    }]
})

var query= {"name" : "USA"}

db.find(query).populate('main').sort({'locations.locid':1}).exe(function(err, records){
   return callback(records);
})

上面提到的代码没有给出任何错误,但是也没有排序。您能否让我知道如何按字段对嵌套数组进行排序。我已经检查了stackoverflow中的其他解决方案,但是它们在不同的位置排序。

0 个答案:

没有答案