我必须在MongoDB中找到4级数组中的更新,比如我的部门页面是一个有多个部门的数组,而我的所有部门都有多个部门,所有部门都有多个指定,所以我只能找到那些满足条件的指定数组,还必须使用推,拉和设置进行更新
示例结构
{
"_id": "5649bb56db5648617ed36556",
"departmentPage": {
"departmentPageInfo": {
"active": "1"
},
"departments": [
{
"_id": "56501d09cbb8a41d27c1c0e4",
"active": 1,
"divisions": [
{
"_id": "56501d69cbb8a49319c1c0e4",
"active": 1,
"departmentId": "56501d09cbb8a41d27c1c0e4",
"designations": [
],
"instanceNo": 1,
"order": 1,
"title": "Php Development Recruitment"
},
{
"_id": "565078edcbb8a44546c1c0e4",
"active": 1,
"departmentId": "56501d09cbb8a41d27c1c0e4",
"designations": [
{
"_id": "56507944cbb8a44546c1c0e5",
"active": 1,
"departmentId": "56501d09cbb8a41d27c1c0e4",
"divisionId": "565078edcbb8a44546c1c0e4",
"instanceNo": 1,
"order": "1",
"title": "Senior php developer"
},
{
"_id": "5650795ccbb8a4b851c1c0e4",
"active": 1,
"departmentId": "56501d09cbb8a41d27c1c0e4",
"divisionId": "565078edcbb8a44546c1c0e4",
"instanceNo": 3,
"order": "1",
"title": "Junior php developer"
}
],
"instanceNo": 2,
"order": "1",
"title": "Php Development "
}
],
"instanceNo": 1,
"order": 1,
"title": "Information Technology (IT)"
},
{
"_id": "56501d33cbb8a41f14c1c0e5",
"active": 1,
"divisions": [
{
"_id": "5652c228cbb8a4e152bfeb99",
"active": 1,
"departmentId": "56501d33cbb8a41f14c1c0e5",
"designations": [
{
"_id": "565305e7cbb8a4ef56bfeb9a",
"instanceNo": 1,
"departmentId": "56501d33cbb8a41f14c1c0e5",
"divisionId": "5652c228cbb8a4e152bfeb99",
"title": "Cashier",
"active": 1,
"order": "1"
},
{
"_id": "5653edaacbb8a4df74bfeb99",
"instanceNo": 2,
"departmentId": "56501d33cbb8a41f14c1c0e5",
"divisionId": "5652c228cbb8a4e152bfeb99",
"title": "Cash Collection Agent",
"active": 1
}
]
}
]
}
]
}
}
这是我试过的:
db.department.aggregate([
{$unwind : '$departmentPage.departments.divisions.designations'},
{$match :
{'departmentPage.departments.divisions.designations._id':ObjectId("")}
}
])
它得到0结果,它工作到部门,但之后它给出0结果