$bitsAnySet

The `$bitsAnySet` operator is used to match documents where any of the specified bit positions are set (that is, are 1). This operator is useful for filtering documents based on at least one bit being set.

Syntax

{
  <field>: { $bitsAnySet: <bitmask> }
}

Parameters

fieldstringrequired

The field in the document on which the bitwise operation is to be performed.

<bitmask>numberrequired

A bitmask indicating which bits should be checked for being set in the field's value.

Examples

Sample Data

{
  "_id": "store1",
  "name": "Store Name",
  "storeFeatures": 5
}

Find stores where any specific feature bit is set

Matches documents where any of the specified bit positions in the storeFeatures field are set (1).

Query:

db.stores.find({
  storeFeatures: { $bitsAnySet: 3 }
})

Output:

[
  {
    "_id": "store1",
    "name": "Store Name",
    "storeFeatures": 5
  }
]

Related