팁
MongoDB는 대량 쓰기 작업을 수행하기 위한 Mongo.bulkWrite() 메서드도 제공합니다.
정의
db.collection.initializeOrderedBulkOp()중요
Mongo쉬 방법
This page documents a
mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.MongoDB API 드라이버의 경우 언어별 MongoDB 드라이버 설명서를 참조하세요.
컬렉션에 대한 새
Bulk()작업 빌더를 초기화하고 반환합니다. 빌더는 MongoDB가 대량으로 실행하는 쓰기 작업을 순서가 지정된 목록으로 구성합니다.반환합니다: 새
Bulk()작업 빌더 객체.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.
행동
작업 순서
순서가 지정된 작업 목록을 사용하여 MongoDB는 목록의 쓰기 작업을 순차적으로 실행합니다.
연산 실행
When executing an ordered list of operations, MongoDB groups the operations by the operation type and contiguity; i.e. contiguous operations of the same type are grouped together. For example, if an ordered list has two insert operations followed by an update operation followed by another insert operation, MongoDB groups the operations into three separate groups: first group contains the two insert operations, second group contains the update operation, and the third group contains the last insert operation. This behavior is subject to change in future versions.
Bulk() operations in mongosh and comparable methods in the drivers do not have a limit for the number of operations in a group. To see how the operations are grouped for bulk operation execution, call Bulk.getOperations() after the execution.
Executing an ordered list of operations on a sharded collection will generally be slower than executing an unordered list since with an ordered list, each operation must wait for the previous operation to finish.
Error Handling
쓰기 작업 중 하나를 처리하는 동안 오류가 발생하더라도 MongoDB는 목록에 있는 나머지 쓰기 작업을 계속 처리합니다.
예시
다음은 users collection에서 Bulk() 작업 빌더를 초기화하고, 일련의 쓰기 작업을 추가하고, 작업을 실행합니다.
var bulk = db.users.initializeOrderedBulkOp(); bulk.insert( { user: "abc123", status: "A", points: 0 } ); bulk.insert( { user: "ijk123", status: "A", points: 0 } ); bulk.insert( { user: "mop123", status: "P", points: 0 } ); bulk.find( { status: "D" } ).delete(); bulk.find( { status: "P" } ).update( { $set: { comment: "Pending" } } ); bulk.execute();