On this page本页内容
$bitsAllClear
¶New in version 3.2.版本3.2中的新功能。
$bitsAllClear
matches documents where all of the bit positions given by the query are clear (i.e. 匹配查询给出的所有位位置在0
) in field
.field
中均为清除(即0
)的文档。
{ <field>: { $bitsAllClear: <numeric bitmask> } } |
{ <field>: { $bitsAllClear: < BinData bitmask> } } |
{ <field>: { $bitsAllClear: [ <position1>, <position2>, ... ] } } |
The field
value must be either numeric or a BinData instance. field
值必须是数字或BinData实例。Otherwise, 否则,$bitsAllClear
will not match the current document.$bitsAllClear
将与当前文档不匹配。
$bitsAllClear
will return an error.$bitsAllClear
将返回一个错误。<position>
must be a non-negative integer. <position>
必须是非负整数。0
from the least significant bit. 0
开始。254
would have the following bit positions:254
将具有以下位位置:Bit Value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Queries cannot use indexes for the 查询不能为查询的$bitsAllClear
portion of a query, although the other portions of a query can use indexes, if applicable.$bitsAllClear
部分使用索引,尽管查询的其他部分可以使用索引(如果适用)。
$bitsAllClear
will not match numerical values that cannot be represented as a signed 64-bit integer. $bitsAllClear
将不匹配不能表示为有符号64位整数的数值。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位整数,或者它有一个分数分量,则可能会出现这种情况。
Numbers are sign extended. 数字是符号扩展的。For example, 例如,$bitsAllClear
considers bit position 200
to be set for the negative number -5
, but bit position 200
to be clear for the positive number +5
.$bitsAllClear
认为位位置200
被设置为负数-5
,但位位置200
被清除为正数+5
。
In contrast, BinData instances are zero-extended. 相比之下,BinData实例是零扩展的。For example, given the following document:例如,给定以下文档:
$bitsAllClear
will consider all bits outside of x
to be clear.$bitsAllClear
将考虑x
以外的所有比特都是清除的。
The following examples will use a collection with the following documents:以下示例将使用包含以下文档的集合:
The following query uses the 下面的查询使用$bitsAllClear
operator to test whether field a
has bits clear at position 1
and position 5
, where the least significant bit is position 0
.$bitsAllClear
运算符来测试字段a
在位置1
和位置5
是否有位清除,其中最低有效位是位置0。
The query matches the following documents:该查询与以下文档匹配:
The following query uses the 以下查询使用$bitsAllClear
operator to test whether field a
has bits clear at positions 0
, 1
, and 5
(the binary representation of the bitmask 35
is 00100011
).$bitsAllClear
运算符测试字段a
在位置0
、1
和5
处是否有位清除(位掩码35的二进制表示形式为00100011
)。
The query matches the following documents:该查询与以下文档匹配:
The following query uses the 下面的查询使用$bitsAllClear
operator to test whether field a
has bits clear at positions 2 and 4 (the binary representation of BinData(0, "ID==")
is 00010100
.$bitsAllClear
运算符来测试字段a
在位置2
和4
处是否有清除位(BinData(0, "ID==")
的二进制表示形式为0000100
。
The query matches the following documents:该查询与以下文档匹配: