在MongoDB中对嵌套数组对象应用$ pull

时间:2018-02-14 10:38:33

标签: jquery node.js mongodb mongoose

我有一个mongoDB对象,它有一个进一步拥有嵌套数组的数组

{
"_id" : ObjectId("5a7d4e16c8e12b396b0efe0b"),
"UserName" : "person",
"ParentArray" : [ 
    {
        "ModuleID" : "1112",
        "_id" : ObjectId("5a7d4e16c8e12b396b0efe17"),
        "ChildArray" : [      {
                "ChildCount" : "0000",
                "name" : "One",
            }
      ],
    }, 
    {
        "ModuleID" : "1113",
        "_id" : ObjectId("5a7d4e16c8e12b396b0efe15"),
        "ChildArray" : [ 
            {
                "ChildCount" : "0001",
                "name" : "two",
            },
{
                "ChildCount" : "0011",
                "name" : "two point two",
            }
        ]
    }, 
    {
        "ModuleID" : "0002",
        "_id" : ObjectId("5a7d4e16c8e12b396b0efe13"),
        "ChildArray" : [ 
            {
                "ChildCount" : "0002",
                "name" : "three",
                "_id" : ObjectId("5a7d4e16c8e12b396b0efe14")
            }
    ,
    {
                "ChildCount" : "0011",
                "name" : "two point two",
            }
        ]
    }
  ]
}

我想在ChildArray中删除一个选定的对象,例如我想要删除一个具有“ChildCount”的对象:0011,“name”:“two point two”

我只有删除双嵌套数组的解决方案,其中包含以下代码{$pull:{"ParentArray.0.ChildArray":{ChildCount:"0000"}}

我找不到任何关于如何在这种情况下应用$pull的文档

0 个答案:

没有答案