How to implement bulkWrite async in Java?
Hi @AARZOO_MANOOSI,
For async, please see MongoDB Java Driver: Reactive Stream. An example of an ordered BulkWrite operations:
// 1. 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>());
Please see also Reactive Stream Tutorials: Bulk Writes for more information
Regards,
Wan.
Thanks and appreciated !!