Multiple Update Subdocument

I would like to make several updates in the "value" field of the subdocument if the "oid" and "instance" fields are the same. I can do this in one sub-folder at a time, but is there a way to do this for several

- It works for one -

db.myTable.update({ "data" : { "$elemMatch" : { "oid" : "1.3.6.1.4.1.111.3.10.2.5.35.3", 
                                                "instance" : "0" } }, 
                    "$atomic" : "true" },
                  { $set: { "data.$.value": "change good" }}, 
                  false, 
                  true);



  "_id" : 483,
  "data" : [{
      "oid" : "1.3.6.1.4.1.111.3.10.2.5.35.3",
      "instance" : "0",
      "value" : "0"
    }, {
      "oid" : "1.3.6.1.4.1.111.3.999.2.5.2",
      "instance" : "0",
      "value" : "aaa"
    }, {
      "oid" : "1.3.6.1.4.1.111.3.30.5.1.1",
      "instance" : "0",
      "value" : "BBB"
    }]}
+5
source share
1 answer

This question has been asked several times already , but no, you cannot do this at a time. To repeat the answer:

You will need to do this yourself in your application code, request a document and intercept all of your attached documents; and then save it back to MongoDB.

, , http://www.mongodb.org/display/DOCS/Atomic+Operations

, MongoDB. , : https://jira.mongodb.org/browse/SERVER-1243

+8

All Articles