在早期版本的 MongoDB Java 驱动程序中,要运行查询并对结果进行无序批量 upsert,我们所做的就是:
BulkWriteOperation bulk = dbCollection.initializeUnorderedBulkOperation();
bulk.find(searchQuery).upsert().update(new BasicDBObject("$set", getDbObjectModel()));
但是在第 3 版中,随着 Bson 文档支持和 MongoCollection.bulkWrite() 方法的引入,如何做到这一点?
我试过这个:
List<WriteModel<Document>> documentList = new ArrayList<>();
collection.bulkWrite(documentList, new BulkWriteOptions().ordered(false));
但是,我需要 upsert 功能。
谢谢。