Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MongoDB UpdateMany Child Array without filter

Mongo Playground

Simple Schema:

[
  {
    "key": 1,
    "Array": [
      {
        "Prop1": 1,
        "Prop2": 2
      },
      {
        "Prop1": 2,
        "Prop2": 3
      },
      
    ]
  },
]

I want to update all child array, but mongo says ‘The positional operator did not find the match needed from the query.’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

db.collection.update({},
{
  "$set": {
    "Array.$.Prop1": ""
  }
},
{
  "multi": true,
  "upsert": false
})

>Solution :

Maybe something like this:

 db.collection.update({},
 {
   "$set": {
     "Array.$[].Prop1": ""
    }
  },
  {
    "multi": true,
    "upsert": false
  })

playground

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading