View a markdown version of this page

인덱스 속성: 희소 - Amazon DocumentDB

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

인덱스 속성: 희소

지원되는 인덱스 유형

옵션 3.6 4.0 5.0 8.0 탄력적 클러스터
단일 필드
compound
다중 키

희소 옵션을 사용하여 인덱싱된 필드가 누락된 문서의 인덱싱을 건너뛰어 인덱스 크기를 줄이고 메모리 공간을 절약할 수 있습니다. 인덱스 크기가 작기 때문에 이를 사용하는 쿼리가 더 효율적입니다. 쿼리가 희소 인덱스를 활용하려면 인덱싱된 필드에 $exists 절을 사용해야 합니다. $exists 절을 생략하면 Amazon DocumentDB는 희소 인덱스를 사용하지 않습니다.

예제

다음 예제에서는 다음 샘플 문서에서 희소 인덱스를 생성하는 방법을 보여줍니다.

{ "productId": "PROD133726", "sku": "SKU24224", "name": "Basic Printer", "manufacturer": "The Manufacturer", "tags": [ "printer", "basic", "electronics", "business" ], "barcodes": [ "542364671", "886330670", "437445606" ], "reviews": [ { "review_date": ISODate('2024-01-19T21:37:10.585Z'), ... } ], "material": "Polycarbonate", "color": "Space Gray", "supplier": { "supplierId": "SUP4", "location": { "type": "Point", "coordinates": [ -71.0589, 42.3601 ] } }, "productEmbedding": [ -0.019320633663838058, 0.019672111388113596 ], "lastUpdated": ISODate('2025-10-20T21:37:10.585Z') }

검토, 재료 및 색상 필드가 모든 문서에 있는 것은 아닙니다.

단일 필드

재료 필드에 희소 단일 필드 인덱스를 생성합니다.

db.collection.createIndex( { "material": 1 }, { "name": "material_sparse", "sparse": true } )

이 인덱스는 재료 값이 있는 모든 제품을 찾을 때 사용됩니다.

db.collection.find({ "material": { $exists: true } })

복합

재료 및 색상 필드에 희소 복합 인덱스를 생성합니다.

db.collection.createIndex( { "material": 1, "color": 1 }, { "name": "material_and_color_sparse", "sparse": true } )

이 인덱스는 재료와 색상 값의 조합이 있는 모든 제품을 찾을 때 사용됩니다.

db.collection.find({ "material": { $exists: true } }) db.collection.find({ "color": { $exists: true } }) db.collection.find({ $and: [ { "material": { $exists: true } }, { "color": { $exists:true } } ] }) db.collection.find({ $and: [ { "color": { $exists: true } }, { "material": { $exists:true } } ] })

다중 키

리뷰 배열에 희소 다중 키 인덱스를 생성합니다.

db.collection.createIndex( { "reviews": 1 }, { "name": "reviews_sparse", "sparse": true } )

이 인덱스는 리뷰 배열이 있는 모든 제품을 찾을 때 사용됩니다.

db.collection.find({ "reviews": { $exists: true } })