In the earlier versions of MongoDB Java drivers , to run a query and do unordered bulk upsert on the result all we had do was :
BulkWriteOperation bulk = dbCollection.initializeUnorderedBulkOperation();
bulk.find(searchQuery).upsert().update(new BasicDBObject("$set", getDbObjectModel()));
But in version 3, with the introduction of Bson Document support and MongoCollection.bulkWrite() method how can this be done?
I tried this :
List<WriteModel<Document>> documentList = new ArrayList<>();
collection.bulkWrite(documentList, new BulkWriteOptions().ordered(false));
but, I need the upsert functionality.
Thanks.