Core Server
  1. Core Server
  2. SERVER-1243

Use positional operator to update all items in an array

    Details

    • # Replies:
      79
    • Last comment by Customer:
      true

      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
          Amine
          added a comment -

          How is this possible with a NoSQL database document oriented to leak this main feature?
          Isn't a document oriented db mainly designed to avoid cross tables/collections queries (that even don't really exists with mognodb...)?
          Isn't a document oriented db mainly designed to save multi-level data in a same document?
          Is it really a P4?
          what an incredible credibility wasting.
          (same thing for the $ that only work for the first array level...)

          Show
          Amine
          added a comment - How is this possible with a NoSQL database document oriented to leak this main feature? Isn't a document oriented db mainly designed to avoid cross tables/collections queries (that even don't really exists with mognodb...)? Isn't a document oriented db mainly designed to save multi-level data in a same document? Is it really a P4? what an incredible credibility wasting. (same thing for the $ that only work for the first array level...)
          Hide
          Jason Marmon
          added a comment -

          +1 Use case:

          I have an array of embedded objects representing customers that we automatically contact. After contacting the customer, we update that embedded document and contact the next one some minutes later. If, however, somehow a second copy of that customer's identifier sneaks into the array, our application contacts this customer over and over until we manually stop it, because only the first copy of the customer's status is updates as 'contacted'.

          I agree with the above sentiment - this should already be implemented. It's a bug that needs to be fixed, not an optional new feature.

          Show
          Jason Marmon
          added a comment - +1 Use case: I have an array of embedded objects representing customers that we automatically contact. After contacting the customer, we update that embedded document and contact the next one some minutes later. If, however, somehow a second copy of that customer's identifier sneaks into the array, our application contacts this customer over and over until we manually stop it, because only the first copy of the customer's status is updates as 'contacted'. I agree with the above sentiment - this should already be implemented. It's a bug that needs to be fixed, not an optional new feature.
          Hide
          Stjepan Buljat
          added a comment -

          +1 this is a must have...

          Show
          Stjepan Buljat
          added a comment - +1 this is a must have...
          Hide
          Björn
          added a comment -

          +1 I need this to update a document schema (introducing a new default field to all documents)

          Show
          Björn
          added a comment - +1 I need this to update a document schema (introducing a new default field to all documents)
          Hide
          Grégoire Aubert
          added a comment -

          +1 This feature really needs to be implemented.

          Show
          Grégoire Aubert
          added a comment - +1 This feature really needs to be implemented.

            Dates

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