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 -

          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...
          Hide
          bakti_pratama bakti added a comment -

          come on guys, you can do it

          Show
          bakti_pratama bakti added a comment - come on guys, you can do it
          Hide
          riteshagarwal100 Ritesh Agarwal added a comment -

          Hi,

          Can this feature be implemented, as we are using nodejs with mongoDb, and fetching large dataset on node thread is very expensive. If there can be a query where all the elements in an embedded array gets updated in one click, it would be a very useful query.

          Thanks
          Ritesh

          Show
          riteshagarwal100 Ritesh Agarwal added a comment - Hi, Can this feature be implemented, as we are using nodejs with mongoDb, and fetching large dataset on node thread is very expensive. If there can be a query where all the elements in an embedded array gets updated in one click, it would be a very useful query. Thanks Ritesh
          Hide
          nunov Nuno added a comment -

          Help

          Show
          nunov Nuno added a comment - Help

            People

            • Votes:
              407 Vote for this issue
              Watchers:
              270 Start watching this issue

              Dates

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