$bitsAnyClear

The `$bitsAnyClear` operator is used to match documents where any of the bit positions specified in a bitmask are clear (that is, 0). This operator is useful for filtering documents based on at least one bit being unset.

Syntax

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

Parameters

fieldstringrequired

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

<bitmask>numberrequired

A bitmask where each bit position specifies the corresponding bit position that should be checked for being clear (0).

Examples

Sample Data

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

Find stores where any specific feature bit is clear

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

Query:

db.stores.find({
  storeFeatures: { $bitsAnyClear: 6 }
})

Output:

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

Related