我想写一个表达式,允许我设置嵌套在另一个文档中的项目的字段checked
。我怎样才能在MongoDB中实现这一目标?
{ "_id" : ObjectId("55081de2162072120758fc53")[
{
"_id": "55081de2162072120758fc53",
"items": [
{
"checked": false,
"name": "Apples",
"_id": "554df987a8e9950134aa72bd"
},
{
"checked": false,
"name": "Jam",
"_id": "554df98ba8e9950134aa72be"
}
}
]
...
}
为了访问单个项目,我执行以下操作:
xy.aggregate([
{$match: {_id: new ObjectId(idlist)}},
{$unwind: '$items'},
{$match: {'items._id': new ObjectId(iditem)}},
{$project: {_id: false, item: '$items'}}
Apples
项设置为false
的查询?