문서 메뉴
문서 홈
/
MongoDB 매뉴얼
/ / /

Bulk.find.hint()

이 페이지의 내용

  • 설명
  • 예제

MongoDB는 대량 쓰기 작업을 수행하기 위한 db.collection.bulkWrite() 메서드도 제공합니다.

Bulk.find.hint()

hint 지원할 인덱스 를 지정하는 Bulk.find() 옵션을 설정합니다.

이 옵션은 인덱스 사양 문서 또는 인덱스 이름 문자열을 사용할 수 있습니다.

존재하지 않는 인덱스를 지정하면 연산 오류가 발생합니다.

Bulk.find.hint() 에 영향을 미치지 않습니다. Bulk.find.removeOne()

예시 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 } } ] )

다음도 참조하세요.

돌아가기

Bulk.find.deleteOne

다음

Bulk.find.remove

이 페이지의 내용