There is a document of this type:

{ "name": "a", "items": [ { "x": "10", "val": "123" }, { "x": "11", "val": "123" }, { "x": "12", "val": "123" } ] } 

I need to change the field "val" in the object, where "x": "11". This object in this case is the second element of the array, but it can be any one in a row. Trying to make a request:

 db.collection("collectionName").update({"name": "a"}, {"..."}) 

What to write instead of dots? How to get to the element with a field "x", equal to 11?

    1 answer 1

     db.collection("collectionName").update({"items.x" : 11}, {"$set" : {"items.$.val" : "any_value"}})