Para agentes de IA: hay un índice de documentación disponible en https://www.mongodb.com/es/docs/llms.txt — versiones en markdown de todas las páginas están disponibles agregando .md a cualquier ruta URL.
Docs Menu

$bitsAllSet (query predicate operador)

$bitsAllSet

$bitsAllSet matches documents where all of the bit positions given by the query are set (i.e. 1) in field.

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

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

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

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

Máscara de bits numérica

Puede proporcionar una máscara de bits numérica que se comparará con el campo del operando. La máscara de bits debe ser un entero con signo de 0 64bits no negativo. De lo contrario, devuelve un$bitsAllSet error.

BinData Bitmask

También puedes usar una instancia BinData arbitrariamente grande como máscara de bits.

Lista de cargos

Si se consulta una lista de posiciones de bits, cada <position> debe ser un número entero no negativo. Las posiciones de bits comienzan en 0 desde el bit menos significativo. Por ejemplo, el número decimal 254 tendría las siguientes posiciones de bits:
Valor de bit
1
1
1
1
1
1
1
0

Posición

7

6

5

4

3

2

1

0

La endianidad de tu sistema depende de la arquitectura de tu equipo. Los números en los datos BSON siempre se almacenan como little-endian, y si tu sistema es big-endian esto significa que los datos numéricos se convierten entre big y little endian.

En el contexto de los operadores de expresiones de coincidencia de prueba de bits:

BinData values act as bitmasks and are interpreted as though they are arbitrary-length unsigned little-endian numbers. The lowest-addressable byte is always interpreted as the least significant byte. Similarly, the highest-addressable byte in the BinData is always interpreted as the most significant byte.

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

$bitsAllSet no coincidirán con valores numéricos que no puedan ser representados como un entero de 64 bits con signo. Este puede ser el caso si un valor es demasiado grande o demasiado pequeño para caber en un entero con signo de 64 bits, o si tiene un componente fraccionario.

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

En cambio, las instancias de BinData tienen una extensión cero. Por ejemplo, dado el siguiente documento:

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

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

Los siguientes ejemplos usarán una colección con los siguientes 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 $bitsAllSet operator to test whether field a has bits set at position 1 and position 5, where the least significant bit is position 0.

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

La query coincide con los siguientes documentos:

{ "_id" : 1, "a" : 54, "binaryValueofA" : "00110110" }
{ "_id" : 4, "a" : BinData(0,"Zg=="), "binaryValueofA" : "01100110" }

The following query uses the $bitsAllSet operator to test whether field a has bits set at positions 1, 4, and 5 (the binary representation of the bitmask 50 is 00110010).

db.collection.find( { a: { $bitsAllSet: 50 } } )

La query coincide con el siguiente documento:

{ "_id" : 1, "a" : 54, "binaryValueofA" : "00110110" }

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

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

La query coincide con el siguiente documento:

{ _id: 1, a: 54, binaryValueofA: "00110110" }
Califique esta página

En esta página