Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
APPLIES TO:
MongoDB vCore
The $bitsAllSet
operator is used to match documents where all the specified bit positions are set (that is, are 1). This operator is useful for performing bitwise operations on fields that store integer values. It can be used in scenarios where you need to filter documents based on specific bits being set within an integer field.
{
<field>: { $bitsAllSet: <bitmask> }
}
<field>
: The field in the document on which the bitwise operation is to be performed.<bitmask>
: A bitmask indicating which bits must be set in the field's value.
Consider a collection named stores
that contains documents with various fields. To find documents where the storeId
field has specific bits set, you can use the $bitsAllSet
operator.
db.stores.find({
"store.storeId": { $bitsAllSet: 0b00000011 }
})
This query would return documents where the storeId
field has both the first and second bits set.
db.stores.find({
"store.staff.totalStaff.fullTime": { $bitsAllSet: 0b00001111 }
})
This query would return documents where the fullTime
field in totalStaff
has the first 4 bits set.
- Review options for Migrating from MongoDB to Azure Cosmos DB for MongoDB (vCore)
- Read more about Feature compatibility with MongoDB