MongoDB 批量插入避免唯一值重复停掉问题

使用唯一索引+insert_many+ordered=false

insert_many方法本质上也是bulk操作,但它较update少了搜索的部分,因此理论上更快。
同时也是因为没有进行搜索就插入,它没有办法判断插入的数据是否存在,这点就需要通过item_id上的唯一索引来确保。
同时默认情况下insert_many使用ordered=true,遇到一个插入错误(item_id重复)就停止了,所以需要ordered=false

原文地址:https://www.cnblogs.com/xibuhaohao/p/12622893.html