multiple object update in array field

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      I have an object array in my document and i want to update them all but mongo update only the first one matching to the update condition

      for example I have a doc :

      { "_id" : ObjectId("590aee020a0556027b14b262"), "x" : [ { "y" : 1 }, { "y" : 1 }, { "y" : 1 }, { "y" : 1 } ] }
      

      Now I am updating this :-

      db.users.update({"x.y":1},{$set:{"x.$.y":2}},{multi:true})
      

      then only get the first object updated :-

      { "_id" : ObjectId("590aee020a0556027b14b262"), "x" : [ { "y" : 2 }, { "y" : 1 }, { "y" : 1 }, { "y" : 1 } ] }
      

            Assignee:
            Unassigned
            Reporter:
            Mayank Tyagi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: