문서 메뉴
문서 홈
/ / /
Java Reactive Streams 드라이버
/ /

대량 쓰기 작업

v2.6 부터 시작됩니다. MongoDB는 드라이버가 BulkWriteResultBulkWriteException 에 대한 올바른 시맨틱을 구현할 수 있는 방식으로 삽입, 업데이트 및 삭제 작업에 대한 대량 쓰기 명령을 지원합니다.

대량 작업에는 순서가 지정된 대량 작업과 순서가 지정되지 않은 대량 작업의 두 가지 유형이 있습니다.

  1. 순서가 지정된 대량 작업은 모든 작업을 순서대로 실행하고 첫 번째 쓰기 오류가 발생하면 오류가 발생합니다.

  2. 순서가 지정되지 않은 대량 작업은 모든 작업을 실행하고 오류를 보고합니다. 순서가 지정되지 않은 대량 작업은 실행 순서를 보장하지 않습니다.

중요

이 가이드에서는 퀵 스타트 프라이머에 설명된 Subscriber 구현을 사용합니다.

다음 코드는 순서가 지정된 작업과 순서가 지정되지 않은 작업을 사용하는 예제를 제공합니다.

// Ordered bulk operation - order is guaranteed
collection.bulkWrite(
Arrays.asList(new InsertOneModel<>(new Document("_id", 4)),
new InsertOneModel<>(new Document("_id", 5)),
new InsertOneModel<>(new Document("_id", 6)),
new UpdateOneModel<>(new Document("_id", 1),
new Document("$set", new Document("x", 2))),
new DeleteOneModel<>(new Document("_id", 2)),
new ReplaceOneModel<>(new Document("_id", 3),
new Document("_id", 3).append("x", 4))))
.subscribe(new ObservableSubscriber<BulkWriteResult>());
// Unordered bulk operation - no guarantee of order of operation
collection.bulkWrite(
Arrays.asList(new InsertOneModel<>(new Document("_id", 4)),
new InsertOneModel<>(new Document("_id", 5)),
new InsertOneModel<>(new Document("_id", 6)),
new UpdateOneModel<>(new Document("_id", 1),
new Document("$set", new Document("x", 2))),
new DeleteOneModel<>(new Document("_id", 2)),
new ReplaceOneModel<>(new Document("_id", 3),
new Document("_id", 3).append("x", 4))),
new BulkWriteOptions().ordered(false))
.subscribe(new ObservableSubscriber<BulkWriteResult>());

돌아가기

쓰기 작업

다음

애그리게이션 프레임워크