The $bit operator performs a bitwise update of a field. Only use this with integer fields, as in the following examples:

db.collection.update( { field: NumberInt(1) }, { $bit: { field: { and: NumberInt(5) } } } );

db.collection.update( { field: NumberInt(1) }, { $bit: { field: { or: NumberInt(5) } } } );

Here, the $bit operator updates the integer value of the field named field: in the first example with a bitwise and: 5 operation; and in the second example with a bitwise or: 5 operation. $bit only works with integers.

$bit only supports AND and OR bitwise operations.


All numbers in the mongo shell are doubles, not integers. Use the NumberInt() constructor to specify integers. See NumberInt for more information.