代码
final BulkOperations bulkOps = fsMongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED, FsFile.class);
List<FsFile> entries = fsMongoTemplate.find(new Query().addCriteria(Criteria.where("owner").is(1588232816247L)), FsFile.class);
entries.stream().filter(entry -> entry != null).forEach(entry -> {
Query query = new Query();
query.addCriteria(Criteria.where("fid").is(entry.getFid()));
Update update = new Update();
update.set("path", String.valueOf(Math.random()));
bulkOps.updateOne(query, update);
});
BulkWriteResult result = bulkOps.execute();
处理结果
{"deletedCount":0,"insertedCount":0,"matchedCount":6,"modifiedCount":6,"modifiedCountAvailable":true,"upserts":[]}
测试结果
path长度为更新字符串长度