gpt4 book ai didi

python - pymongo.errors.BulkWriteError : batch op errors occurred (MongoDB 3. 4.2,pymongo 3.4.0,python 2.7.13)

转载 作者:行者123 更新时间:2023-11-28 17:18:00 27 4
gpt4 key购买 nike

我正在使用 pymongo 将数亿条格式为 {'id_str': , 'created_at': , 'text': } 的推文从文本文件迁移到 MongoDB。为每个用户创建一个集合来存储他/她的推文。我使用的插入方法是insert_many()。它经常遇到 BulkWriteError

Traceback (most recent call last):
File "pipeline.py", line 105, in <module>
timeline_db, meta_db, negative_db, log_col, dir_path)
File "/media/haitao/Storage/twitter_pipeline/migrate_old.py", line 134, in migrate_dir
timeline_db[user_id].insert_many(utility.temporal_sort(statuses))
File "/home/haitao/anaconda3/envs/py27/lib/python2.7/site-packages/pymongo/collection.py", line 711, in insert_many
blk.execute(self.write_concern.document)
File "/home/haitao/anaconda3/envs/py27/lib/python2.7/site-packages/pymongo/bulk.py", line 493, in execute
return self.execute_command(sock_info, generator, write_concern)
File "/home/haitao/anaconda3/envs/py27/lib/python2.7/site-packages/pymongo/bulk.py", line 331, in execute_command
raise BulkWriteError(full_result)
pymongo.errors.BulkWriteError: batch op errors occurred

这个错误好像是key重复的时候出现的,这里应该不是这样的。我可以检查其他事项来解决此问题吗?

提前致谢!

最佳答案

抱歉耽搁了。

1) 我重现了错误。以下接近 mongod.log 的末尾。

I -        [ftdc] Assertion: 13538:couldn't open [/proc/5774/stat] errno:24 Too many open
files
W FTDC [ftdc] Uncaught exception in 'Location13538: couldn't open [/proc/5774/stat]
errno:24 Too many open files' in full-time diagnostic data capture subsystem. Shutting down
the full-time diagnostic data capture subsystem.
E STORAGE [conn2] WiredTiger (24) [1491020356:127332][5774:0x7f6f30e9d700], WT_SESSION
.create: /var/lib/mongodb/: directory-sync: open: Too many open files
I COMMAND [conn2] command timeline_db.231731006 command: insert { insert: "231731006",
ordered: true, documents: 1000 } ninserted:0 keyUpdates:0 writeConflicts:0 exception: 24:
Too many open files code:8 numYields:0 reslen:123 locks:{ Global: { acquireCount: { r: 2,
w: 2 } }, Database: { acquireCount: { w: 1, W: 1 } }, Collection: { acquireCount: { w: 1,
W: 1 } } } protocol:op_query 511ms```

2) 是的,只传递了一个 MongoClient() 实例。

3) 没有运行多处理。

在我发布初始问题后,我开始使用 insert_one(),它明确引发了打开文件限制错误。我更改了数据库的设计(主要是减少了集合的数量)并解决了打开文件限制的问题。我不确定,但日志似乎表明 BulkWriteError 的实际原因也是打开文件限制。

关于python - pymongo.errors.BulkWriteError : batch op errors occurred (MongoDB 3. 4.2,pymongo 3.4.0,python 2.7.13),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43073956/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com