Why updatemany function is not working?

what i’m doing wrong?
db.products.updateMany({"images.url":"sampleURL"},{$set : {"images.url":"aaa"}})

Your images property is an array of objects. So you can NOT update the field of an array. But you can update the field of each item in an array.

So, if you want to update the first item in an array, you would do it like this:

  { "images.url": "sampleURL" },
  { $set : { "images.0.url": "new_url" } }
1 Like

Since the query part queries the array you may use

1 Like

Definitely better solution. :smile:

but isn’t $update for for updating only a single value?

If $ does not work in updateMany, which I cannot test right now, you may use the arrayFilters: option of updateMany.