[英]mongodb order/$sort by array entry
項目架構:
var ItemSchema = new Schema({
name: {type : String},
possibleorders: [{
name: {type : String},
value: {type : Number}
}]
})
如何通過具有特定名稱的可能訂單值對項目進行排序/$排序?
您可以嘗試使用聚合框架。
db.collectionName.aggregate([
{$unwind: "$possibleorders"},
{$sort: {"possibleorders.name":1}},
{$group: {_id:"$_id",name:"$name", possibleorders: {$push:"$possibleorders"}}}
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.