$bitsAllClear$bitsAllClearmatches documents where all of the bit positions given by the query are clear (i.e.0) infield.{ <field>: { $bitsAllClear: <numeric bitmask> } }{ <field>: { $bitsAllClear: <BinDatabitmask> } }{ <field>: { $bitsAllClear: [ <position1>, <position2>, ... ] } }The
fieldvalue must be either numeric or aBinDatainstance. Otherwise,$bitsAllClearwill not match the current document.- 숫자 비트마스크
- 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,
$bitsAllClearreturns an error. - BinData Bitmask
- 임의로 큰
BinData인스턴스를 비트마스크로 사용할 수도 있습니다. - 위치 목록
- 비트 위치 목록을 쿼리하는 경우 각
<position>은 음수가 아닌 정수여야 합니다. 비트 위치는 최하위 비트에서0부터 시작합니다. 예를 들어 10진수254의 비트 위치는 다음과 같습니다.
비트 값11111110직위
7
6
5
4
3
2
1
0
행동
시스템의 엔디안 은 머신의 아키텍처에 따라 달라집니다. BSON 데이터의 숫자는 항상 리틀 엔디안 으로 저장되며, 시스템이 빅 엔디안 인 경우 숫자 데이터가 빅 엔디안과 리틀 엔디안 간에 변환됩니다.
비트 테스트 일치 표현식 연산자의 컨텍스트에서:
BinData 값은 비트마스크 역할을 하며 임의의 길이의 부호 없는 리틀 엔디안 숫자처럼 해석됩니다. 주소 지정 가능한 최하위 바이트는 항상 최하위 바이트로 해석됩니다. 마찬가지로 BinData 에서 주소 지정 가능한 가장 높은 바이트는 항상 최상위 바이트로 해석됩니다.
Indexes
Queries cannot use indexes for the $bitsAllClear portion of a query, although the other portions of a query can use indexes, if applicable.
부동 소수점 값
$bitsAllClear 는 부호 있는 64비트 정수로 표시할 수 없는 숫자 값과 일치하지 않습니다. 값이 너무 크거나 너무 작아서 부호 있는 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.
대조적으로 BinData 인스턴스는 0 확장됩니다. 예를 들어 다음 문서가 있다고 가정해 보겠습니다.
db.collection.insertOne({ x: BinData(0, "ww=="), binaryValueofA: "11000011" })
$bitsAllClear will consider all bits outside of x to be clear.
예시
다음 예시에서는 다음 문서와 함께 컬렉션을 사용합니다.
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 $bitsAllClear operator to test whether field a has bits clear at position 1 and position 5, where the least significant bit is position 0.
db.collection.find( { a: { $bitsAllClear: [ 1, 5 ] } } )
쿼리가 다음 문서와 일치합니다.
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" } { "_id" : 3, "a" : 20, "binaryValueofA" : "00010100" }
Integer Bitmask
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).
db.collection.find( { a: { $bitsAllClear: 35 } } )
쿼리가 다음 문서와 일치합니다.
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" } { "_id" : 3, "a" : 20, "binaryValueofA" : "00010100" }
BinData Bitmask
The following query uses the $bitsAllClear operator:
db.collection.find( { a: { $bitsAllClear: BinData(0, "IA==") } } )
쿼리:
BinData의 첫 번째 값으로0를 지정하며, 이는IA==를 바이너리로 해석해야 함을 나타냅니다. 바이너리 단위로 base-64 값IA==는00100000이며, 위치 5에1가 있습니다.Uses
$bitsAllClearto return documents where theafield has a clear bit0in position 5 of the binary value.
이 쿼리는 다음 문서를 반환합니다.
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" } { "_id" : 3, "a" : 20, "binaryValueofA" : "00010100" }