# How to perform a bulkWrite?
import com.mongodb.client.model._
val writeModelList: java.util.List[WriteModel[Document]] =
new util.ArrayList[WriteModel[Document]]()
//insert a row
val lotteryToInsert = LotteryRow(lotteryName = "Bulk Lottery",
participantList = List("Ram", "Lakshman", "Shiv"), open = true)
writeModelList.add(
new InsertOneModel[Document](lotteryToInsert.toDocument)
)
//update option 1 with basic Document object
writeModelList.add(
new UpdateOneModel[Document](
new Document("lotteryName", "SAMPLE Update"), // find part
new Document("$set", new Document("open", true)), // update part
new UpdateOptions().upsert(true) // options like upsert
))
//update option 2 using SMILE DML support
val q = LotteryQuery().open.is(true)
val u = LotteryUpdate().participantList.addToSet("Admin")
writeModelList.add(
new UpdateManyModel[Document](
q.toDocument, // find part
u.toDocument // update part
))
val bulkWriteResult = LotteryWriter().collection.bulkWrite(writeModelList)
bulkWriteResult.println
REFERENCE