[SERVER-3046] $bit update modifier doesn't work when field does not exist Created: 05/May/11  Updated: 12/Jul/16  Resolved: 20/Nov/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.8.1
Fix Version/s: 2.5.3

Type: Bug Priority: Major - P3
Reporter: Robert Stam Assignee: David Storch
Resolution: Done Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-3223 $bit won't do an upsert Closed
Operating System: ALL
Participants:

 Description   

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 }

>



 Comments   
Comment by James Hartig [ 14/Mar/14 ]

Any chance of backporting this to 2.4 or 2.2? There isn't really a workaround for this without doing a lookup first.

Comment by Scott Hernandez (Inactive) [ 20/Nov/13 ]

Looks like there is already a test here https://github.com/mongodb/mongo/blob/master/jstests/verify_update_mods.js#L55

Comment by David Storch [ 20/Nov/13 ]

This is fixed in 2.5.3. I will add a js test before resolving.

Generated at Thu Feb 08 03:01:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.