mongodb 批量更新BulkOperations 并发是报错“requests can not contain a null value”

在项目中不能用并发循环类似parallelStream().

BulkOperations bulkOps = mongoTemplate.bulkOps(BulkOperations.BulkMode.ORDERED, Object.class, collectionName);
cacheEntities.parallelStream().forEach(comGoods -> {
    Criteria criteria=Criteria.where("companyId").is(comGoods.getCompanyId()).and("goodsId").is(comGoods.getGoodsId());
    Update update = new Update();
    //更新内容
    update.set("goodsPrice", comGoods.getGoodsPrice());
    update.set("goodsSalePrice", comGoods.getGoodsSalePrice());
    update.set("goodsMarketPrice", comGoods.getGoodsMarketPrice());
    update.set("IntegralPrice", comGoods.getIntegralPrice());
    update.set("isShow", comGoods.getIsShow());
    update.set("profitRate", comGoods.getProfitRate());
    update.set("sort", comGoods.getSort());
    update.set("typeId", comGoods.getTypeId());
    bulkOps.updateOne(Query.query(criteria), update);
});

改成普通的for循环就不会报错

相关文章

MongoTemplate 是Spring Data MongoDB 中的一个核心类,为 S...
笔者今天要分享的是一个项目重构过程中如何将数据库选型由原...
1.类型区别MySQL是传统的关系型数据库,MongoDB则是非关系型...
在mongodb数据库中操作字段的方法:1.启动mongodb;2.登录mo...
在mongodb中查看指定时间段数据的方法:1.启动mongodb;2.登...
在mongodb中给数据按时间进行排序的方法:1.启动mongodb服务...