$bitsAllClear - Amazon DocumentDB

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

$bitsAllClear

Amazon DocumentDB의 $bitsAllClear 연산자는 필드의 지정된 모든 비트가 지워지는 문서와 일치시키는 데 사용됩니다(0으로 설정). 이 연산자는 저장된 데이터에 대해 비트 단위 작업을 수행하는 데 유용할 수 있습니다.

파라미터

  • field: 지워지는 지정된 비트를 확인할 필드입니다.

  • value: 확인할 비트 또는 확인할 비트 위치 목록을 지정하는 숫자 비트 마스크입니다. 숫자 비트마스크는 바이너리(0b...), 십진수, 16진수(0x...), 8진수(0o...) 또는 바이너리(BinData) 형식일 수 있습니다. 비트 위치 목록에서 가장 중요하지 않은 비트의 위치는 0입니다.

예제(MongoDB 쉘)

다음 예제에서는 Amazon DocumentDB에서 $bitsAllClear 연산자의 사용을 보여줍니다.

샘플 문서 생성

db.collection.insertMany([ { _id: 1, bits: 0b1010 }, { _id: 2, bits: 0b1100 }, { _id: 3, bits: 0b0101 } ]);

쿼리 예제

db.collection.find({ bits: { $bitsAllClear: 0b0011 } })

출력

{ "_id" : 2, "bits" : 12 }

쿼리는 비트 마스크에 의해 지정된 모든 비트0b0011(가장 중요하지 않은 두 비트)가 bits 필드에서 지워지는지 확인합니다. bits 필드의 비트가 지워져 있으므로 _id 2가 있는 문서는이 조건을 충족합니다.

코드 예제

$bitsAllClear 명령을 사용하기 위한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

Node.js
const { MongoClient } = require('mongodb'); async function example() { const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); const db = client.db('test'); const collection = db.collection('collection'); const result = await collection.find({ bits: { $bitsAllClear: 0b0011 } }).toArray(); console.log(result); await client.close(); } example();
Python
from pymongo import MongoClient def example(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client['test'] collection = db['collection'] result = list(collection.find({ 'bits': { '$bitsAllClear': 0b0011 } })) print(result) client.close() example()