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
          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. !!!
          Hide
          dvideby0 Richard Brookfield added a comment -

          Can someone from the Mongo team report when they think they will be able to assign someone to this issue? Please and Thank you!

          Show
          dvideby0 Richard Brookfield added a comment - Can someone from the Mongo team report when they think they will be able to assign someone to this issue? Please and Thank you!
          Hide
          Sergei Bershadsky Sergei Bershadsky added a comment -

          Really missing this feature

          Show
          Sergei Bershadsky Sergei Bershadsky added a comment - Really missing this feature
          Hide
          Rajesh Rajesh Kumar added a comment -

          Really need this feature in MongoDB while doing bulk update

          Show
          Rajesh Rajesh Kumar added a comment - Really need this feature in MongoDB while doing bulk update
          Hide
          hranjc1 Christopher Hranj added a comment -

          I just ran into this issue during my first time ever using a database. The use case for this is very evident. Please assign someone to this. It's been five years....

          Show
          hranjc1 Christopher Hranj added a comment - I just ran into this issue during my first time ever using a database. The use case for this is very evident. Please assign someone to this. It's been five years....

            Dates

            • Created:
              Updated:
              Days since reply:
              4 weeks, 5 days ago
              Date of 1st Reply: