Remove an object from a nested array with $pull and $[identifier] (mongoDB 3.6)

后端 未结 1 711
时光说笑
时光说笑 2021-01-20 01:30

MongoDB 3.6 allow to perform complex array manipulations against all matching elements in any array – no matter how deeply nested – Update Nested Arrays with $[identifier]

相关标签:
1条回答
  • 2021-01-20 02:14

    Try positional all $[] variant.

    Something like

    db.runCommand({
      update: "survey",
      updates: [
        {
          q: {},
          u: {
            $pull: {
              "results.$[].items.$[].comments": { "id":  "123456" }
            }
          }
        }
      ]
    })
    
    0 讨论(0)
提交回复
热议问题