연 $bitsAllClear 산자는 비트 마스크에 지정된 모든 비트 위치가 명확한 문서(즉, 0)를 일치시키는 데 사용됩니다. 이 연산자는 필드의 이진 표현에서 설정되지 않은 특정 비트를 기반으로 문서를 필터링해야 하는 시나리오에서 유용합니다.
문법
{
<field>: { $bitsAllClear: <bitmask> }
}
매개 변수
| 매개 변수 | Description |
|---|---|
field |
비트 연산을 수행할 문서의 필드입니다. |
<bitmask> |
각 비트 위치가 필드 값에서 명확해야 하는 해당 비트 위치를 지정하는 비트 마스크(0)입니다. |
예시
스토어 컬렉션에서 이 샘플 문서를 고려합니다.
{
"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
"name": "First Up Consultants | Beverage Shop - Satterfieldmouth",
"location": {
"lat": -89.2384,
"lon": -46.4012
},
"staff": {
"totalStaff": {
"fullTime": 8,
"partTime": 20
}
},
"sales": {
"totalSales": 75670,
"salesByCategory": [
{
"categoryName": "Wine Accessories",
"totalSales": 34440
},
{
"categoryName": "Bitters",
"totalSales": 39496
},
{
"categoryName": "Rum",
"totalSales": 1734
}
]
},
"promotionEvents": [
{
"eventName": "Unbeatable Bargain Bash",
"promotionalDates": {
"startDate": {
"Year": 2024,
"Month": 6,
"Day": 23
},
"endDate": {
"Year": 2024,
"Month": 7,
"Day": 2
}
},
"discounts": [
{
"categoryName": "Whiskey",
"discountPercentage": 7
},
{
"categoryName": "Bitters",
"discountPercentage": 15
},
{
"categoryName": "Brandy",
"discountPercentage": 8
},
{
"categoryName": "Sports Drinks",
"discountPercentage": 22
},
{
"categoryName": "Vodka",
"discountPercentage": 19
}
]
},
{
"eventName": "Steal of a Deal Days",
"promotionalDates": {
"startDate": {
"Year": 2024,
"Month": 9,
"Day": 21
},
"endDate": {
"Year": 2024,
"Month": 9,
"Day": 29
}
},
"discounts": [
{
"categoryName": "Organic Wine",
"discountPercentage": 19
},
{
"categoryName": "White Wine",
"discountPercentage": 20
},
{
"categoryName": "Sparkling Wine",
"discountPercentage": 19
},
{
"categoryName": "Whiskey",
"discountPercentage": 17
},
{
"categoryName": "Vodka",
"discountPercentage": 23
}
]
}
]
}
storeFeatures 필드는 다양한 저장소 기능을 나타내는 비트 마스크 정수입니다. 각 비트는 기능에 해당합니다.
| 비트 | 가치 | 특징 |
|---|---|---|
| 0 | 1 | In-Store 픽업 |
| 1 | 2 | 주차 |
| 2 | 4 | 휠체어 이용 |
| 3 | 8 | 24시간 열기 |
| 4 | 16 | Pet-Friendly |
| 5 | 32 | 무료 Wi-Fi |
| 6 | 64 | 화장실 |
| 7 | 128 | 택배 |
예제 1: 24시간 열지 않고 애완동물을 허용하지 않는 매장 찾기
이 쿼리는 24시간 동안 열리지 않고 애완 동물을 허용하지 않는 저장소를 검색합니다(비트 3 및 4).
db.stores.find({
storeFeatures: {
$bitsAllClear: [3, 4]
}
}, {
_id: 1,
name: 1,
storeFeatures: 1
}).limit(5)
해당:
db.stores.find({
storeFeatures: {
$bitsAnySet: 24
}
}, // 8 + 16
{
_id: 1,
name: 1,
storeFeatures: 1
}).limit(5)
이 쿼리에서 반환된 처음 5개의 결과는 다음과 같습니다.
[
{
"_id": "a715ab0f-4c6e-4e9d-a812-f2fab11ce0b6",
"name": "Lakeshore Retail | Holiday Supply Hub - Marvinfort",
"storeFeatures": 38
},
{
"_id": "94792a4c-4b03-466b-91f6-821c4a8b2aa4",
"name": "Fourth Coffee | Eyewear Shop - Lessiemouth",
"storeFeatures": 225
},
{
"_id": "1a2c387b-bb43-4b14-a6cd-cc05a5dbfbd5",
"name": "Contoso, Ltd. | Smart Home Device Vault - Port Katarina",
"storeFeatures": 36
},
{
"_id": "e88f0096-4299-4944-9788-695c40786d97",
"name": "Adatum Corporation | Handbag Shoppe - Lucienneberg",
"storeFeatures": 135
},
{
"_id": "bfb213fa-8db8-419f-8e5b-e7096120bad2",
"name": "First Up Consultants | Beauty Product Shop - Hansenton",
"storeFeatures": 135
}
]
관련 콘텐츠
- MongoDB에서 Azure DocumentDB로 마이그레이션하기 위한 옵션을 검토합니다.
- MongoDB와의 기능 호환성에 대해 자세히 알아보세요.