$bitsAllClear는 에서 쿼리 에 의해 제공된
$bitsAllClear모든 비트 위치가 명확한 문서(예:)와0일치합니다.field{ <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.- 숫자 비트마스크
- 피연산자 필드 와 일치시킬 숫자 비트마스크를 제공할 수 있습니다. 비트 마스크는 음수가 64아닌 비트 부호 있는 정수여야 합니다. 그렇지 않으면 이(가)
$bitsAllClear오류를 반환합니다. - BinData Bitmask
- 임의로 큰
BinData인스턴스를 비트마스크로 사용할 수도 있습니다. - 위치 목록
- 비트 위치 목록을 쿼리하는 경우 각
<position>은 음수가 아닌 정수여야 합니다. 비트 위치는 최하위 비트에서0부터 시작합니다. 예를 들어 10진수254의 비트 위치는 다음과 같습니다.
비트 값11111110직위
7
6
5
4
3
2
1
0
행동
시스템의 엔디안 은 머신의 아키텍처에 따라 달라집니다. BSON 데이터의 숫자는 항상 리틀 엔디안 으로 저장되며, 시스템이 빅 엔디안 인 경우 숫자 데이터가 빅 엔디안과 리틀 엔디안 간에 변환됩니다.
비트 테스트 일치 표현식 연산자의 컨텍스트에서:
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.
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" } ])
비트 위치 배열
다음 쿼리 연산자 사용하여 필드 $bitsAllClear a의 1 위치와 위치(최하위 5 비트가 위치)에 비워 있는 비트가 있는지 0 테스트합니다.
db.collection.find( { a: { $bitsAllClear: [ 1, 5 ] } } )
쿼리가 다음 문서와 일치합니다.
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" } { "_id" : 3, "a" : 20, "binaryValueofA" : "00010100" }
Integer Bitmask
다음 쿼리 연산자 사용하여 $bitsAllClear a 0필드, 1 및 위치에 비워진 비트가 있는지 5 테스트합니다(비트마스크 의 이진 35 표현은 00100011 임).
db.collection.find( { a: { $bitsAllClear: 35 } } )
쿼리가 다음 문서와 일치합니다.
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" } { "_id" : 3, "a" : 20, "binaryValueofA" : "00010100" }
BinData Bitmask
다음 쿼리 연산자 사용합니다.$bitsAllClear
db.collection.find( { a: { $bitsAllClear: BinData(0, "IA==") } } )
쿼리:
BinData의 첫 번째 값으로0를 지정하며, 이는IA==를 바이너리로 해석해야 함을 나타냅니다. 바이너리 단위로 base-64 값IA==는00100000이며, 위치 5에1가 있습니다.$bitsAllClear를a05 사용하여 필드 이진 값의 위치에 클리어 비트가 있는 문서를 반환합니다.
이 쿼리는 다음 문서를 반환합니다.
{ "_id" : 2, "a" : 20, "binaryValueofA" : "00010100" } { "_id" : 3, "a" : 20, "binaryValueofA" : "00010100" }