我的收藏结构
{
"companyName": "iAssure",
"companyDepartment": [
{
"Department": "IT",
"companysubDepartment": [
"HR",
"Finance",
"Account"
]
},
{
"Department": "Production",
"companysubDepartment": [
"Raw Material",
"Quality"
]
}
]
}
我想从HR
删除部门companysubDepartment
IT
答案 0 :(得分:0)
您在更新中错过了$ operator。
检查以下查询:
db.companySettings.update({'_id':"9uvjCujcjSbbLYi86","companyDepartment":
{"$elemMatch":{"Department":"IT"}}},
{"$pull":{"companyDepartment.$.companysubDepartment":"HR"}})