문서 메뉴
문서 홈
/ / /
Scala
/ /

대량 쓰기 작업

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

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

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

참고

이 가이드에서는 퀵 스타트 프라이머에서 다루는 Observable 암시를 사용합니다.

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

import org.mongodb.scala._
import org.mongodb.scala.model._
// Ordered bulk operation - order is guaranteed
collection.bulkWrite(
List(InsertOneModel(Document("_id" -> 4)),
InsertOneModel(Document("_id" -> 5)),
InsertOneModel(Document("_id" -> 6)),
UpdateOneModel(Document("_id" -> 1), Document("$set", Document("x" -> 2))),
DeleteOneModel(Document("_id" -> 2)),
ReplaceOneModel(Document("_id"-> 3), Document("_id" -> 3, "x" -> 4)))
).printResults()
// Unordered bulk operation - no guarantee of order of operation
collection.bulkWrite(
List(InsertOneModel(Document("_id" -> 4)),
InsertOneModel(Document("_id" -> 5)),
InsertOneModel(Document("_id" -> 6)),
UpdateOneModel(Document("_id" -> 1), Document("$set", Document("x" -> 2))),
DeleteOneModel(Document("_id" -> 2)),
ReplaceOneModel(Document("_id"-> 3), Document("_id" -> 3, "x" -> 4))),
BulkWriteOptions().ordered(false)
).printResults()

돌아가기

쓰기 작업

다음

애그리게이션 프레임워크