mongodb 批量插入唯一索引冲突

 

 

https://stackoverflow.com/questions/10388540/insert-or-ignore-multiple-documents-in-mongodb

 

使用 insert 

try:
    coll.insert(
        doc_or_docs=doc_array,
        continue_on_error=True)
except pymongo.errors.DuplicateKeyError:
    pass

 

 

使用 insert_many

    try:
        table.insert_many(arr, ordered=False)
    except pymongo.errors.BulkWriteError:
        pass

 

posted @ 2021-03-08 16:40  AngDH  阅读(641)  评论(0编辑  收藏  举报