Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用$pull和$[identifier](mongoDB 3.6)从嵌套数组中删除对象_Mongodb - Fatal编程技术网

使用$pull和$[identifier](mongoDB 3.6)从嵌套数组中删除对象

使用$pull和$[identifier](mongoDB 3.6)从嵌套数组中删除对象,mongodb,Mongodb,MongoDB 3.6允许对任何数组中的所有匹配元素执行复杂的数组操作-无论嵌套有多深- 考虑以下关于调查收集的文档: { "_id": "5a7d86d8fac139e71b0b9f5b", "results": [ { "items": [ { "comments": [ { "id" : "123456", "e

MongoDB 3.6允许对任何数组中的所有匹配元素执行复杂的数组操作-无论嵌套有多深-

考虑以下关于
调查
收集的文档:

{
    "_id": "5a7d86d8fac139e71b0b9f5b",
    "results": [
      {
        "items": [
          {
            "comments": [
              {
                "id" : "123456",
                "email": "user@email.com",
                "comment": "comment 1"
              }
            ]
          }
        ]
      }
    ]
  }
我正在尝试使用
$pull
和新的
$[]
删除基于注释
id
的注释

我尝试了下面的
命令
,基于:

但它不起作用,因为
$pull
需要一个数组值:
无法对非数组值应用$pull

有什么帮助吗?谢谢。

试试变体

差不多

db.runCommand({
  update: "survey",
  updates: [
    {
      q: {},
      u: {
        $pull: {
          "results.$[].items.$[].comments": { "id":  "123456" }
        }
      }
    }
  ]
})
db.runCommand({
  update: "survey",
  updates: [
    {
      q: {},
      u: {
        $pull: {
          "results.$[].items.$[].comments": { "id":  "123456" }
        }
      }
    }
  ]
})