$bitsAnyClear$bitsAnyClearmatches documents where any of the bit positions given by the query are clear (i.e.匹配字段中查询给出的任何位位置都是明确的(即0) infield.0)的文档。{ <field>: { $bitsAnyClear: <numeric bitmask> } }{ <field>: { $bitsAnyClear: <BinDatabitmask> } }{ <field>: { $bitsAnyClear: [ <position1>, <position2>, ... ] } }Thefieldvalue must be either numeric or aBinDatainstance. Otherwise,$bitsAnyClearwill not match the current document.field值必须是数字或BinData实例。否则,$bitsAnyClear将与当前文档不匹配。Numeric Bitmask数字位掩码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,您可以提供与操作数字段匹配的数字位掩码。位掩码必须是非负的64位带符号整数。否则,$bitsAnyClearreturns an error.$bitsAnyClear将返回错误。- BinData
Bitmask位掩码 You can also use an arbitrarily large您还可以使用任意大的BinDatainstance as a bitmask.BinData实例作为位掩码。Position List职位列表If querying a list of bit positions, each如果查询位位置列表,则每个<position>must be a non-negative integer. Bit positions start at0from the least significant bit. For example, the decimal number254would have the following bit positions:<position>必须是非负整数。位位置从最低有效位的0开始。例如,十进制数254将具有以下位位置:
Bit Value位值1 1 1 1 1 1 1 0 Position位置7 6 5 4 3 2 1 0
Behavior行为
The endianness of your system depends on the architecture of your machine. 系统的端序取决于机器的架构。Numbers in BSON data are always stored as little-endian, if your system is big-endian this means that numeric data is converted between big and little endian.BSON数据中的数字始终以小端存储,如果系统是大端,这意味着数字数据在大端和小端之间转换。
In the context of the bit-test match expression operators:在比特测试匹配表达式运算符的上下文中:
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.BinData中最高可寻址字节始终被解释为最高有效字节。
Indexes索引
Queries cannot use indexes for the 查询不能对查询的$bitsAnyClear portion of a query, although the other portions of a query can use indexes, if applicable.$bitsAnyClear部分使用索引,但查询的其他部分可以使用索引(如果适用)。
Floating Point Values浮点值
$bitsAnyClear will not match numerical values that cannot be represented as a signed 64-bit integer. This can be the case if a value is either too large or too small to fit in a signed 64-bit integer, or if it has a fractional component.将不匹配不能表示为带符号64位整数的数值。如果一个值太大或太小,无法容纳一个有符号的64位整数,或者它有一个分数分量,则可能会出现这种情况。
Sign Extension符号扩展
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.$bitsAnyClear认为位位置200设置为负数-5,但位位置200为正数+5。
In contrast, 相比之下,BinData instances are zero-extended. For example, given the following document:BinData实例是零扩展的。例如,给定以下文档:
db.collection.insertOne({ x: BinData(0, "ww=="), binaryValueofA: "11000011" })
$bitsAnyClear will consider all bits outside of 将认为x to be clear.x之外的所有位都是清晰的。
Examples示例
The following examples will use a collection with the following documents:以下示例将使用包含以下文档的集合:
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" }
])
Bit Position Array位位置数组
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.$bitsAnyClear运算符来测试字段a的位位置是1还是5,其中最低有效位是位置0。
db.collection.find( { a: { $bitsAnyClear: [ 1, 5 ] } } )
The query matches the following documents:查询匹配以下文档:
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" }
{ "_id" : 3, "a" : 20.0, "binaryValueofA" : "00010100" }Integer Bitmask整数位掩码
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).$bitsAnyClear运算符来测试字段a在位置0、1和5是否有任何位清除(位掩码35的二进制表示为00100011)。
db.collection.find( { a: { $bitsAnyClear: 35 } } )
The query matches the following documents:查询匹配以下文档:
{ "_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" }BinData Bitmask位掩码
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).$bitsAnyClear运算符来测试字段a在位置4和5是否有任何位是空的(BinData(0, "MA==")的二进制表示为00110000)。
db.collection.find( { a: { $bitsAnyClear: BinData(0, "MA==") } } )
The query matches the following documents:查询匹配以下文档:
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" }
{ "_id" : 3, "a" : 20.0, "binaryValueofA" : "00010100" }
{ "_id" : 4, "a" : BinData(0,"Zg=="), "binaryValueofA" : "01100110" }