无法在 pymongo 中打开安全的情况下插入
以下代码运行没有问题。
collection.insert(file_cont)
以下代码运行w问题如下:
collection.insert(file_cont, safe=True)
Traceback (most recent call last):
File "/home/user/Documents/Python/Python_MongoDB/connect_db.py", line 102, in <module>
patterns="*.[zZ][iI][pP]")
File "/home/user/Documents/Python/Python_MongoDB/connect_db.py", line 93, in fs_load_data_to_db
collection.insert(file_cont, safe=True)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.0.1-py2.7-linux-i686.egg/pymongo/collection.py", line 283, in insert
check_keys, safe, kwargs), safe)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.0.1-py2.7-linux-i686.egg/pymongo/message.py", line 75, in insert
data += "".join(encoded)
MemoryError
问题1>如何解决这个问题?
问题2>我应该使用 insert(sth, safe=True) 还是 insert(sth) ?
The following code runs w/o problems.
collection.insert(file_cont)
The following code runs w problems as follows:
collection.insert(file_cont, safe=True)
Traceback (most recent call last):
File "/home/user/Documents/Python/Python_MongoDB/connect_db.py", line 102, in <module>
patterns="*.[zZ][iI][pP]")
File "/home/user/Documents/Python/Python_MongoDB/connect_db.py", line 93, in fs_load_data_to_db
collection.insert(file_cont, safe=True)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.0.1-py2.7-linux-i686.egg/pymongo/collection.py", line 283, in insert
check_keys, safe, kwargs), safe)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.0.1-py2.7-linux-i686.egg/pymongo/message.py", line 75, in insert
data += "".join(encoded)
MemoryError
Question 1> How to fix this problem?
Question 2> should I use insert(sth, safe=True) or insert(sth)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎正在尝试将太大的文件插入数据库。
根据 pymongo 文档,
安全
参数意味着:因此,理论上您应该期望引发
OperationFailure
,但您获得的是MemoryError
,标准 python 错误 这意味着:当您说
collection.insert(file_cont)
有效时,也许代码有效,但在数据库中的插入却默默地失败了。您应该检查尝试插入数据库的内容的大小以及计算机上的可用内存。It looks like you're trying to insert a too big file into your database.
According to the pymongo documentation, the
safe
parameter means :So, in theory you should expect an
OperationFailure
to be raised, but what you obtain is aMemoryError
, a standard python error that means :When you said that
collection.insert(file_cont)
works, maybe the code works, but the insertion in database silently fails. You should check the size of what you try to insert in your database, and the available memory you have on your computer.这和安全有什么关系?你的内存不足了(就像与愚蠢的Python编程有关)......完全不相关
What has this to do with safe? You are running out of memory (like related to stupid Python programming)...completely unrelated