【发布时间】:2017-07-18 07:36:02
【问题描述】:
我有疑问:
Model.aggregate([{
$lookup: {
from: 'translations',
localField: '_id',
foreignField: 'item_id',
as: 'translation'
},
}, {
$project: {
"label": "$label",
"items": "$items",
"translation": {
"$filter": {
"input": "$translation",
"as": "page",
"cond": {
"$eq": ["$$page.lang_key", lang]
}
}
}
}
}])
结果:
[ { _id: 58b2ca5b9ac42bac7aaed48a,
label: 'Main',
items: [ [Object] ],
translation: [ [Object] ] } ]
如何使字段translation 不是数组?
因为我总是只收到 Array 中的一个元素...
【问题讨论】:
标签: node.js mongodb mongoose mongodb-query aggregation-framework