Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-3046

$bit update modifier doesn't work when field does not exist

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.3
    • Affects Version/s: 1.8.1
    • Component/s: Write Ops
    • Labels:
      None
    • ALL

      The $bit update modifier doesn't work when field does not exist. In this case it also causes other update modifiers to be ignored. To be consistent with other modifieds (like $inc) it should probably treat a nonexistent field as an implied zero.

      To reproduce:

      > // $bit or should work if field doesn't exist:
      > db.test.insert(

      {x:1}

      )
      > db.test.find()

      { "_id" : ObjectId("4dc29da73691b2a95024293b"), "x" : 1 }

      > db.test.update({}, { $bit : { or :

      { y : 2 }

      }}) // y does not exist
      > db.test.find()

      { "_id" : ObjectId("4dc29da73691b2a95024293b"), "x" : 1 }

      >
      > // $bit with field that doesn't exist causes other modifiers to be ignored
      > db.test.update({}, { $set :

      { x : 2 }

      , $bit : { or :

      { y : 2 }

      }}) // y does not exist
      > db.test.find()

      { "_id" : ObjectId("4dc29da73691b2a95024293b"), "x" : 1 }

      >
      > // $bit with field that doesn't exist causes other modifiers to be ignored
      > db.test.update({}, { $set :

      { x : 2 }

      , $bit : { and :

      { y : 2 }

      }}) // y does not exist, $set of x is ignored
      > db.test.find()

      { "_id" : ObjectId("4dc29da73691b2a95024293b"), "x" : 1 }

      >

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: