项目架构:
var ItemSchema = new Schema({
name: {type : String},
possibleorders: [{
name: {type : String},
value: {type : Number}
}]
})
如何通过具有特定名称的可能订单的值来订购/ $对项目进行排序?
答案 0 :(得分:1)
您可以尝试使用聚合框架。
db.collectionName.aggregate([
{$unwind: "$possibleorders"},
{$sort: {"possibleorders.name":1}},
{$group: {_id:"$_id",name:"$name", possibleorders: {$push:"$possibleorders"}}}
]);