mongoTemplate不同数据的批量更新操作
解决方法:
假如200更改了200条数据,每条数据改变的字段和值都不一样该怎么批量更新呢?如下所示:
List<Pair<Query, Update>> updateList = new ArrayList<>();
for(;;){
Query query = new Query(new Criteria("_id").is(doc.get("_id").toString()));
Update update = new Update();
update.set("errorCode", "confirm");
Pair<Query, Update> updatePair = Pair.of(query, update);
updateList.add(updatePair);
}
BulkOperations operations = template.bulkOps(BulkOperations.BulkMode.UNORDERED, SmsReceiver.class);
operations.upsert(updateList);
operations.execute();