Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1243

Use positional operator to update all items in an array

    Details

      Description

      Given the following:

      > var obj = t.findOne()
      { "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC",
        "comments" : [ { "by" : "joe", "votes" : 3 }, { "by" : "jane", "votes" : 7 } ] }
      

      One should be able to modify each item in the comments array by using an update command like the following:

      > t.update( obj, {$set:{'comments.$.votes':1}}, false, true )
      > t.find()
      { "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC",
        "comments" : [ { "by" : "joe", "votes" : 1 }, { "by" : "jane", "votes" : 1 } ] }
      

        Issue Links

          Activity

          Hide
          demonodojo Jose Miguel Díez de la Lastra added a comment -

          Priority changed! Thank you.

          Show
          demonodojo Jose Miguel Díez de la Lastra added a comment - Priority changed! Thank you.
          Hide
          pierrebaz Pierre Bazoge added a comment -

          Could be nice to have an operator like $$ or $all to update all the subdocs. Thanks for the priority update by the way.

          Show
          pierrebaz Pierre Bazoge added a comment - Could be nice to have an operator like $$ or $all to update all the subdocs. Thanks for the priority update by the way.
          Hide
          bifter William Roscoe added a comment -

          For me this is such an important core feature it seems very odd it hasn't been implemented yet.

          Show
          bifter William Roscoe added a comment - For me this is such an important core feature it seems very odd it hasn't been implemented yet.
          Hide
          macheeus Xiaoning Chen added a comment - - edited

          How to let Mongodb know it is such an important missing feature needed by many people. The array operation isn't powerful enough to handle use cases. Please seriously consider users needs.

          Show
          macheeus Xiaoning Chen added a comment - - edited How to let Mongodb know it is such an important missing feature needed by many people. The array operation isn't powerful enough to handle use cases. Please seriously consider users needs.
          Hide
          d.sudhakar540 Sudhakar Reddy added a comment -

          The lack of support/workarounds on this from the mongodb team is ridiculous.
          Updating more than one element in an array is clearly a common requirement.
          and yet its been here for years as a minor issue. !!!

          Show
          d.sudhakar540 Sudhakar Reddy added a comment - The lack of support/workarounds on this from the mongodb team is ridiculous. Updating more than one element in an array is clearly a common requirement. and yet its been here for years as a minor issue. !!!

            Dates

            • Created:
              Updated:
              Days since reply:
              11 hours, 41 minutes ago
              Date of 1st Reply: