Core Server
  1. Core Server
  2. SERVER-1050

not allowed to $push and $pop to same field in same update

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Minor - P4 Minor - P4
    • Resolution: Unresolved
    • Affects Version/s: 1.4.0
    • Fix Version/s: Planning Bucket B
    • Component/s: Write Ops
    • Labels:
      None
    • Backport:
      No
    • # Replies:
      19
    • Last comment by Customer:
      true

      Description

      Was just talking about #991 with Dwight and noticed that you can't workaround by doing $push / $pop to the same field on the same update, for example:

      > db.test.drop();
      false
      > db.test.save(

      { mylist: [1,2] }

      );
      > db.test.update( {}, { $push:

      { mylist: 3 }

      , $pop:

      { mylist: -1 }

      } );
      Field name duplication not allowed with modifiers

      Would be nice if this was permitted.

        Issue Links

          Activity

          Hide
          Philipp Heinze
          added a comment -

          Kekoa Vincent,

          you may avoid the race Condition if you make the updates atomic by adding a temporary lock with the first update which is then removed with the second, so no two Threads may perform this operation for one document at the same time. Though you need some error handling for that in your app. Anyway this ticket needs to be resolved.

          Show
          Philipp Heinze
          added a comment - Kekoa Vincent, you may avoid the race Condition if you make the updates atomic by adding a temporary lock with the first update which is then removed with the second, so no two Threads may perform this operation for one document at the same time. Though you need some error handling for that in your app. Anyway this ticket needs to be resolved.
          Hide
          Debarshi Mukherjee
          added a comment -

          My vote is there for this. This would be really useful to have. Trying to implement a kind of versioning strategy for mongo documents and though there may be other ways to bypass this current limitation, the end solution won't unfortunately be so tight.

          Show
          Debarshi Mukherjee
          added a comment - My vote is there for this. This would be really useful to have. Trying to implement a kind of versioning strategy for mongo documents and though there may be other ways to bypass this current limitation, the end solution won't unfortunately be so tight.
          Hide
          RobertWHurst
          added a comment -

          This is a rather important issue. Is there any progress on this issue thus far? I'd like to remove the ugly hack we have in our orm to split diffs with both $pullAll and $push.

          Show
          RobertWHurst
          added a comment - This is a rather important issue. Is there any progress on this issue thus far? I'd like to remove the ugly hack we have in our orm to split diffs with both $pullAll and $push.
          Hide
          RobertWHurst
          added a comment -

          bump

          Show
          RobertWHurst
          added a comment - bump
          Hide
          Kevin J. Rice
          added a comment - - edited

          I'm using an array to do padding for me. I want to start out with 'offsets' as an array of 100 elems, then pop off it each time I insert in 'vals'. this is fine, normally, I push vals and pop offsets. But, I want to do an upsert, and it apparently won't let me do setOnInsert of (offsets = array of 100 elems) AND pop from offsets (the normal case):

          retval = self.colname.update(
              { 'xx' : 'aa' },
              { '$push' : {'vals' : datapoint}, 
                 '$pop'  : {'offsets' : 1},
                 '$setOnInsert' : { 'offsets' : offsets },
               }, upsert = True, multi = False, w = writeConcern )
          

          I get the error:

          OperationFailure: Field name duplication not allowed with modifiers

          Show
          Kevin J. Rice
          added a comment - - edited I'm using an array to do padding for me. I want to start out with 'offsets' as an array of 100 elems, then pop off it each time I insert in 'vals'. this is fine, normally, I push vals and pop offsets. But, I want to do an upsert, and it apparently won't let me do setOnInsert of (offsets = array of 100 elems) AND pop from offsets (the normal case): retval = self.colname.update( { 'xx' : 'aa' }, { '$push' : {'vals' : datapoint}, '$pop' : {'offsets' : 1}, '$setOnInsert' : { 'offsets' : offsets }, }, upsert = True, multi = False, w = writeConcern ) I get the error: OperationFailure: Field name duplication not allowed with modifiers

            People

            • Votes:
              103 Vote for this issue
              Watchers:
              65 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since reply:
                9 weeks ago
                Date of 1st Reply: