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循环就不会报错

猜你喜欢

转载自blog.csdn.net/qq_18630487/article/details/89526069