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

New operator to update all matching items in an array

    Details

      Description

      Issue Status as of Aug 19, 2015

      MongoDB appreciates the challenge of maintaining applications utilizing schemas with large arrays, especially with respect to updating many or all array elements, and we very much recognize the interest from the community around this ticket.

      Unfortunately, to implement such a major feature there are serious requirements:

      • a specification for new language features (like update modifiers or expressions), since we cannot break existing uses
      • should be included with support to match all array elements, as well was those matching a query
        • requests for support to update the last element(s) could be considered.
      • must support all existing update modifiers (correctly, and in a non-backwards-breaking way)
        • $rename, $set, $unset, $pull, $push, $bit...
      • must work efficiently with all arrays, including those having thousands of elements
      • cannot change current update semantics or behaviors which existing applications and deployments depend on (= non-backwards-breaking).

      In summary, adding this as a new feature, or improvement, is not trivial. It will require resources which are currently working on other projects, and in short is a matter of prioritization over other parts of the whole server.

      Please see this comment below for additional details.

      Original 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
          adambuczynski Adam Buczynski added a comment - - edited

          Well, guess I'm late to the party, but it's still very disappointing to find out that this issue hasn't been addressed in 6 years time.
          Basically what has been said above:

          > As much as I love this database in general, it is embarrassing that this very fundamental and must-have feature (especially because this approach is recommended per design of mongo) is still not available after 5 years! It doesn't matter how you implement it, it will still be faster as to do it in the code.

          After reading a MongoDB blog about denormalization, I thought I'd give it a go and see how it works. Everything was going great until I had to do an update in an array of denormalized data, and then I realized it's impossible to do with one query.

          This is really a must have feature, especially if you're recommending data denormalization in your blogs.

          PS: What's even more problematic, is that this doesn't just not work for updating multiple items in one array, it also doesn't work for updating a single item in an array for multiple documents.

          Show
          adambuczynski Adam Buczynski added a comment - - edited Well, guess I'm late to the party, but it's still very disappointing to find out that this issue hasn't been addressed in 6 years time. Basically what has been said above: > As much as I love this database in general, it is embarrassing that this very fundamental and must-have feature (especially because this approach is recommended per design of mongo) is still not available after 5 years! It doesn't matter how you implement it, it will still be faster as to do it in the code. After reading a MongoDB blog about denormalization, I thought I'd give it a go and see how it works. Everything was going great until I had to do an update in an array of denormalized data, and then I realized it's impossible to do with one query. This is really a must have feature, especially if you're recommending data denormalization in your blogs. PS: What's even more problematic, is that this doesn't just not work for updating multiple items in one array, it also doesn't work for updating a single item in an array for multiple documents.
          Hide
          joymufeng joymufeng added a comment -

          Yes, it's a must-have feature.

          Show
          joymufeng joymufeng added a comment - Yes, it's a must-have feature.
          Hide
          vishallochan Ravi added a comment -

          Yes I also felt, this is some thing missing in MongoDB

          Show
          vishallochan Ravi added a comment - Yes I also felt, this is some thing missing in MongoDB
          Hide
          blented@gmail.com Grant Miller added a comment -

          Definitely disappointed as well. As others have said, inability to do this goes against the entire idea of MongoDB. I honestly thought something was broken when it didn't work, such a basic requirement.

          What do the developers propose as a workaround? Save I have 5 comments and want to mark all as read, how would I write that query? 5 updates?

          Show
          blented@gmail.com Grant Miller added a comment - Definitely disappointed as well. As others have said, inability to do this goes against the entire idea of MongoDB. I honestly thought something was broken when it didn't work, such a basic requirement. What do the developers propose as a workaround? Save I have 5 comments and want to mark all as read, how would I write that query? 5 updates?
          Hide
          adambuczynski Adam Buczynski added a comment -

          Perhaps it's left unfixed intentionally, given how most MongoDB hosts charge you by the number of operations you perform...

          Show
          adambuczynski Adam Buczynski added a comment - Perhaps it's left unfixed intentionally, given how most MongoDB hosts charge you by the number of operations you perform...

            People

            • Votes:
              388 Vote for this issue
              Watchers:
              257 Start watching this issue

              Dates

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