Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.
Menu Docs

$bitsAnyClear (operador de predicado da query)

$bitsAnyClear

$bitsAnyClear matches documents where any of the bit positions given by the query are clear (i.e. 0) in field.

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

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

{ <field>: { $bitsAnyClear: [ <position1>, <position2>, ... ] } }

The field value must be either numeric or a BinData instance. Otherwise, $bitsAnyClear will not match the current document.

Máscara de bits numérica

You can provide a numeric bitmask to be matched against the operand field. The bitmask must be a non-negative 64-bit signed integer. Otherwise, $bitsAnyClear returns an error.

Máscara de bits BinData

Você também pode usar uma instância deBinData arbitrariamente grande como uma máscara de bits.

Lista de posições

Ao consultar uma lista de posições de bits, cada <position> deve ser um número inteiro não negativo. As posições dos bits começam em 0 a partir do bit menos significativo. Por exemplo, o número decimal 254 teria as seguintes posições de bits:
Valor de bits
1
1
1
1
1
1
1
0

Posição

7

6

5

4

3

2

1

0

A endianidade do seu sistema depende da arquitetura da sua máquina. Os números nos dados BSON são sempre armazenados como little-endian, se o seu sistema for big-endian , isso significa que os dados numéricos são convertidos entre big e little endian.

No contexto dos operadores de expressão de correspondência de teste de bit:

BinData valores agem como bitmasks e são interpretados como se fossem números little-endian sem sinal de comprimento arbitrário. O byte endereçável mais baixo é sempre interpretado como o byte menos significativo. Da mesma forma, o byte endereçável de maior valor no BinData é sempre interpretado como o byte mais significativo.

Queries cannot use indexes for the $bitsAnyClear portion of a query, although the other portions of a query can use indexes, if applicable.

$bitsAnyClear não corresponderá a valores numéricos que não possam ser representados como um número inteiro de 64 bits assinado. Esse pode ser o caso se um valor for muito grande ou muito pequeno para caber em um inteiro de 64 bits assinado ou se tiver um componente fracionário.

Numbers are sign extended. For example, $bitsAnyClear considers bit position 200 to be set for the negative number -5, but bit position 200 to be clear for the positive number +5.

Por outro lado, instâncias BinData são estendidas a zero. Por exemplo, dado o seguinte documento:

db.collection.insertOne({ x: BinData(0, "ww=="), binaryValueofA: "11000011" })

$bitsAnyClear will consider all bits outside of x to be clear.

Os exemplos a seguir utilizarão uma coleção com os seguintes documentos:

db.collection.insertMany([
{ _id: 1, a: 54, binaryValueofA: "00110110" },
{ _id: 2, a: 20, binaryValueofA: "00010100" },
{ _id: 3, a: 20.0, binaryValueofA: "00010100" },
{ _id: 4, a: BinData(0, "Zg=="), binaryValueofA: "01100110" }
])

The following query uses the $bitsAnyClear operator to test whether field a has either bit position 1 or bit position 5 clear, where the least significant bit is position 0.

db.collection.find( { a: { $bitsAnyClear: [ 1, 5 ] } } )

A consulta corresponde aos seguintes documentos:

{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" }
{ "_id" : 3, "a" : 20.0, "binaryValueofA" : "00010100" }

The following query uses the $bitsAnyClear operator to test whether field a has any bits clear at positions 0, 1, and 5 (the binary representation of the bitmask 35 is 00100011).

db.collection.find( { a: { $bitsAnyClear: 35 } } )

A consulta corresponde aos seguintes documentos:

{ "_id" : 1, "a" : 54, "binaryValueofA" : "00110110" }
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" }
{ "_id" : 3, "a" : 20.0, "binaryValueofA" : "00010100" }
{ "_id" : 4, "a" : BinData(0,"Zg=="), "binaryValueofA" : "01100110" }

The following query uses the $bitsAnyClear operator to test whether field a has any bits clear at positions 4 and 5 (the binary representation of BinData(0, "MA==") is 00110000).

db.collection.find( { a: { $bitsAnyClear: BinData(0, "MA==") } } )

A consulta corresponde aos seguintes documentos:

{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" }
{ "_id" : 3, "a" : 20.0, "binaryValueofA" : "00010100" }
{ "_id" : 4, "a" : BinData(0,"Zg=="), "binaryValueofA" : "01100110" }
Avalie esta página