$bitsAllSet$bitsAllSetmatches documents where all of the bit positions given by the query are set (i.e.1) infield.{ <field>: { $bitsAllSet: <numeric bitmask> } }{ <field>: { $bitsAllSet: <BinDatabitmask> } }{ <field>: { $bitsAllSet: [ <position1>, <position2>, ... ] } }The
fieldvalue must be either numeric or aBinDatainstance. Otherwise,$bitsAllSetwill not match the current document.- 숫자 비트마스크
- 피연산자 필드 와 일치시킬 숫자 비트마스크를 제공할 수 있습니다. 비트 마스크는 음수가 64아닌 비트 부호 있는 정수여야 합니다. 그렇지 않으면 이(가)
$bitsAllSet오류를 반환합니다. - 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 $bitsAllSet portion of a query, although the other portions of a query can use indexes, if applicable.
부동 소수점 값
$bitsAllSet 는 부호 있는 64비트 정수로 표시할 수 없는 숫자 값과 일치하지 않습니다. 값이 너무 크거나 너무 작아서 부호 있는 64비트 정수에 맞지 않거나 분수 구성 요소가 있는 경우가 이에 해당할 수 있습니다.
부호 확장
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.
대조적으로 BinData 인스턴스는 0 확장됩니다. 예를 들어 다음 문서가 있다고 가정해 보겠습니다.
db.collection.insertOne({ x: BinData(0, "ww=="), binaryValueofA: "11000011" })
$bitsAllSet 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 $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 ] } } )
쿼리가 다음 문서와 일치합니다.
{ "_id" : 1, "a" : 54, "binaryValueofA" : "00110110" } { "_id" : 4, "a" : BinData(0,"Zg=="), "binaryValueofA" : "01100110" }
Integer Bitmask
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 } } )
쿼리가 다음 문서와 일치합니다.
{ "_id" : 1, "a" : 54, "binaryValueofA" : "00110110" }
BinData Bitmask
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==") } } )
쿼리가 다음 문서와 일치합니다.
{ _id: 1, a: 54, binaryValueofA: "00110110" }