We've decided to implement a few bit-test query operators:
$bitsAllSet - matches if the input bit positions are all 1
$bitsAllClear - matches if the input bit positions are all 0
$bitsAnySet - matches if any of the bit positions are 1
$bitsAnyClear - matches if any of the bit positions are 0
These operators can take an array of bit positions, a 64-bit number bitmask, or a BinData bitmask. For the number and BinData bitmasks, the bit positions to check are the positions of 1's in their binary representation.
The operators will only match against int32, int64, doubles, and binary data. Other types will not match.
Note that bit position 0 means the least significant bit.
An example using the array of bit positions syntax:
db.foo.insert( { a: 43 } ); // Binary form: 101011 (leading zeroes truncated)
db.foo.find( { a: { $bitsAllSet: [0, 1, 3] } }, { _id: 0, a: 1 } );
Result: { a: 43 }
An example using the bitmask syntax:
db.foo.insert( { a: 43 } ); // Binary form: 101011 (leading zeroes truncated) db.foo.find( { a: { $bitsAllSet: 9 } }, { _id: 0, a: 1 } ); // Binary form of the bitmask: 1001 Result: { a: 43 }
- is duplicated by
-
SERVER-8657 Add bitfied operators to query and update
- Closed
- is related to
-
DRIVERS-252 Bitwise query operators
- Closed
-
SERVER-24749 Add index support for Bitwise query operations
- Backlog
-
SERVER-3281 Support $bit operator for binary types
- Backlog
- related to
-
CSHARP-1409 Bitwise query operators
- Closed
-
JAVA-1962 Add support for bitwise query operators to Filters builder
- Closed
-
DRIVERS-235 Query Builder Support for 3.2
- Closed
-
SERVER-25823 Add bitwise AND, OR, XOR to aggregation pipeline
- Closed
- links to