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
    • # Replies:
      23
    • 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
          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
          Hide
          Thomas Boutell
          added a comment -

          +1. Just hit this in the same scenario as Michael Dwan. When propagating permissions changes it makes sense to remove some and add some at the same time, and it's not a good idea to have competing threads doing it.

          Show
          Thomas Boutell
          added a comment - +1. Just hit this in the same scenario as Michael Dwan. When propagating permissions changes it makes sense to remove some and add some at the same time, and it's not a good idea to have competing threads doing it.
          Hide
          Eric Roberts
          added a comment -

          Similar scenario as Kevin Rice. I need to upsert a variable amount of values into arrays but pad to a default max in a single call.

          Show
          Eric Roberts
          added a comment - Similar scenario as Kevin Rice. I need to upsert a variable amount of values into arrays but pad to a default max in a single call.
          Hide
          Neil S
          added a comment -
          Show
          Neil S
          added a comment - Also related to https://jira.mongodb.org/browse/SERVER-2643 I think
          Hide
          rene mena
          added a comment -

          +1

          Show
          rene mena
          added a comment - +1

            People

            • Votes:
              134 Vote for this issue
              Watchers:
              86 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since reply:
                24 weeks, 3 days ago
                Date of 1st Reply: