실행 순서를 위해 제어를 사용하여 대량으로 쓰기 작업을 수행합니다. 삽입, 업데이트 및 삭제 작업에 대한 명령이 포함된 IN 메시지 본문으로 List<WriteModel<Document >>가 필요합니다.
다음 예제는 새로운 과학자 "Pierre Curie"를 삽입하고, "Cierre Curie" 필드의 값을 "Marie Curie"로 설정하고 id "3"으로 레코드를 삭제하여 id "5"로 레코드를 업데이트합니다.
// route: from("direct:bulkWrite").to("mongodb:myDb?database=science&collection=notableScientists&operation=bulkWrite");
List<WriteModel<Document>> bulkOperations = Arrays.asList(
new InsertOneModel<>(new Document("scientist", "Pierre Curie")),
new UpdateOneModel<>(new Document("_id", "5"),
new Document("$set", new Document("scientist", "Marie Curie"))),
new DeleteOneModel<>(new Document("_id", "3")));
BulkWriteResult result = template.requestBody("direct:bulkWrite", bulkOperations, BulkWriteResult.class);
// route: from("direct:bulkWrite").to("mongodb:myDb?database=science&collection=notableScientists&operation=bulkWrite");
List<WriteModel<Document>> bulkOperations = Arrays.asList(
new InsertOneModel<>(new Document("scientist", "Pierre Curie")),
new UpdateOneModel<>(new Document("_id", "5"),
new Document("$set", new Document("scientist", "Marie Curie"))),
new DeleteOneModel<>(new Document("_id", "3")));
BulkWriteResult result = template.requestBody("direct:bulkWrite", bulkOperations, BulkWriteResult.class);
Copy to ClipboardCopied!Toggle word wrapToggle overflow
기본적으로 작업은 순서대로 실행되며 목록의 나머지 쓰기 작업을 처리하지 않고 첫 번째 쓰기 오류에서 중단됩니다. MongoDB에서 목록의 남은 쓰기 작업을 계속 처리하도록 지시하려면 CamelMongoDbBulkOrdered IN 메시지 헤더를 false 로 설정합니다. 순서가 지정되지 않은 작업은 병렬로 실행되며 이 동작은 보장되지 않습니다.