Bulk.find.hint()
팁
MongoDB는 대량 쓰기 작업을 수행하기 위한 db.collection.bulkWrite()
메서드도 제공합니다.
설명
Bulk.find.hint()
를
hint
지원할 인덱스 를 지정하는Bulk.find()
옵션을 설정합니다.이 옵션은 인덱스 사양 문서 또는 인덱스 이름 문자열을 사용할 수 있습니다.
존재하지 않는 인덱스를 지정하면 연산 오류가 발생합니다.
Bulk.find.hint()
에 영향을 미치지 않습니다.Bulk.find.removeOne()
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하십시오.
예시
예시 collection orders
을(를) 생성합니다.
db.orders.insertMany( [ { "_id" : 1, "item" : "abc", "price" : NumberDecimal("12"), "quantity" : 2, "type": "apparel" }, { "_id" : 2, "item" : "jkl", "price" : NumberDecimal("20"), "quantity" : 1, "type": "electronics" }, { "_id" : 3, "item" : "abc", "price" : NumberDecimal("10"), "quantity" : 5, "type": "apparel" }, { "_id" : 4, "item" : "abc", "price" : NumberDecimal("8"), "quantity" : 10, "type": "apparel" }, { "_id" : 5, "item" : "jkl", "price" : NumberDecimal("15"), "quantity" : 15, "type": "electronics" } ] )
예제 collection에 다음 인덱스를 생성합니다.
db.orders.createIndex( { item: 1 } ); db.orders.createIndex( { item: 1, quantity: 1 } ); db.orders.createIndex( { item: 1, price: 1 } );
다음 대량 작업은 다양한 문서 업데이트/바꾸기 작업에 사용할 다른 인덱스를 지정합니다.
var bulk = db.orders.initializeUnorderedBulkOp(); bulk.find({ item: "abc", price: { $gte: NumberDecimal("10") }, quantity: { $lte: 10 } }).hint({item: 1, quantity: 1}).replaceOne( { item: "abc123", status: "P", points: 100 } ); bulk.find({ item: "abc", price: { $gte: NumberDecimal("10") }, quantity: { $lte: 10 } }).hint({item: 1, price: 1}).updateOne( { $inc: { points: 10 } } ); bulk.execute();
사용된 인덱스를 보려면 $indexStats
파이프라인을 사용할 수 있습니다.
db.orders.aggregate( [ { $indexStats: { } }, { $sort: { name: 1 } } ] )
다음도 참조하세요.