Pymongo几周来一直很好,直到我遇到以下错误:
Traceback (most recent call last): File "main.py", line 14, in main() File "main.py", line 11, in main downloader.process() File "/mnt/vdisk/crawler/eurostat/downloader.py", line 25, in process self.processHelper() File "/mnt/vdisk/crawler/eurostat/downloader.py", line 61, in processHelper self.base.insert(documents) File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 359, in insert continue_on_error, self.__uuid_subtype), safe) File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 852, in _send_message rv = self.__check_response_to_last_error(response) File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 793, in __check_response_to_last_error raise DuplicateKeyError(details["err"]) pymongo.errors.DuplicateKeyError: E11000 duplicate key error index: test.eurostatdata.$_id_ dup key: { : ObjectId('50fd056757b924675af21a0e') }
_id绝对不是该领域之一。我总是依靠mongodb来生成自己的_id,所以我之前从未遇到过这种问题。
插入代码:
documents = [] for key in split_table_data: document = ele document["title"] = ele["title"] document["table_data"] = split_table_data[key] document["cols"] = colsHeader document["subTitles"] = key documents.append(document) self.base.insert(documents)
我使用最新的pymongo包和最新的mongodb。
唯一可能导致此问题的是我尝试插入超出大小限制的文档。
我试过了
db.repairDatabase()
db.test.validate()