从mongodb

时间:2016-12-02 12:09:58

标签: mongodb

我的收藏结构

{
        "companyName": "iAssure",
        "companyDepartment": [
           {
              "Department": "IT",
              "companysubDepartment": [
                  "HR",
                  "Finance",
                  "Account"
              ]
           },
           {
              "Department": "Production",
              "companysubDepartment": [
                  "Raw Material",
                  "Quality"
              ]
           }
        ]
    }

我想从HR删除部门companysubDepartment

IT

1 个答案:

答案 0 :(得分:0)

您在更新中错过了$ operator

检查以下查询:

db.companySettings.update({'_id':"9uvjCujcjSbbLYi86","companyDepartment":
                          {"$elemMatch":{"Department":"IT"}}},
                          {"$pull":{"companyDepartment.$.companysubDepartment":"HR"}})