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
          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...
          Hide
          jmccormick.me Jonathan added a comment -

          We understand that it's not a small change, but the fact that the platform is unable to do basic operations like this is super lame. Come on Mongo...

          Show
          jmccormick.me Jonathan added a comment - We understand that it's not a small change, but the fact that the platform is unable to do basic operations like this is super lame. Come on Mongo...

            People

            • Votes:
              393 Vote for this issue
              Watchers:
              259 Start watching this issue

              Dates

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