mongo insert_many BulkWriteError



Mongo Insert_many Bulkwriteerror



問題:

データを挿入するときのMongo、問題に書き込まれたメッセージ。次の情報が与えられます。

Traceback (most recent call last): File '/root/crs/call_history_crawler/worker/communicate.py', line 149, in insert_db_data if db[table].insert_many(data): File '/root/crs/call_history_crawler/venv/lib/python2.7/site-packages/pymongo/collection.py', line 684, in insert_many blk.execute(self.write_concern.document) File '/root/crs/call_history_crawler/venv/lib/python2.7/site-packages/pymongo/bulk.py', line 470, in execute return self.execute_command(sock_info, generator, write_concern) File '/root/crs/call_history_crawler/venv/lib/python2.7/site-packages/pymongo/bulk.py', line 314, in execute_command raise BulkWriteError(full_result) BulkWriteError: batch op errors occurred

分析

同じテキストの複数の挿入についての問題、公式声明:insert_many() with a list of references to a single document raises BulkWriteError



>>> doc = {} >>> collection.insert_many(doc for _ in range(10)) Traceback (most recent call last): ... pymongo.errors.BulkWriteError: batch op errors occurred >>> doc {'_id': ObjectId('560f171cfba52279f0b0da0c')} >>> docs = [{}] >>> collection.insert_many(docs * 10) Traceback (most recent call last): ... pymongo.errors.BulkWriteError: batch op errors occurred >>> docs [{'_id': ObjectId('560f1933fba52279f0b0da0e')}]

著者:Chihwei_hsu
ソース: http://chihweihsu.com
Github: https://github.com/HsuChihwei