Good afternoon! After using bulk upsert now our application is 5 to 10 times faster. However, because one course of MongoDB University and other sources say that bulk operations may partially fail in rare instance, we really need to check if a bulk upsert fails or not. For the following code snippet using Spring Data MongoDB:
BulkWriteResult bulkUpsert(List<Product> products) {
BulkOperations bulkOperations = template.bulkOps(BulkOperations.BulkMode.UNORDERED, Product.class);
products.forEach(product -> {
Query query = new Query().addCriteria(Criteria.where("_id").is(product.id));
bulkOperations.replaceOne(query, product, FindAndReplaceOptions.options().upsert());
});
return bulkOperations.execute();
}
after each call to bulkUpsert() how can we know whether MongoDB has successfully executed the bulk operation? Do we always get an exception when MongoDB fails to upsert the documents partially?
Thanks a lot, in advance!
Daniel Li