Python中的Mongodb批量插入限制 [英] Mongodb bulk insert limit in Python

查看:377
本文介绍了Python中的Mongodb批量插入限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PyMongo可以批量插入的文档数量是否受到限制?我并不是说MongoDB的文档大小限制为16mb,而是我希望通过Python批量插入的文档列表的实际大小.

Is there a limit to the number of documents one can bulk insert with PyMongo? And I don't mean the 16mb limit of document size for MongoDB, but the actual size of the list of documents I wish to insert in bulk through Python.

推荐答案

通过pymongo批量插入的文档的数量没有限制.根据 docs ,您可以为collection.insert,它将

There is no limit on the number of documents for bulk insert via pymongo. According to the docs, you can provide an iterable to the collection.insert, and it will

insert each document in the iterable, sending only a single command to the server

关键是pymongo会通过向mongodb服务器发送一个message来尝试插入.

Key point here is that pymongo will try to do your insert by sending one single message to the mongodb server.

Mongodb本身具有消息大小限制(maxMessageSizeBytes),等于48000000字节(maxBsonObjectSize * 3).

Mongodb itself has a message size limit (maxMessageSizeBytes), that is equal to 48000000 bytes (maxBsonObjectSize * 3).

因此,pymongo客户端驱动程序应负责将您的大邮件拆分为较小的邮件,以适应mongodb的最大大小限制.但是,实际上它尚未实现.参见:

So, pymongo client driver should be responsible for splitting your large message into smaller messages to fit into mongodb max size limit. But, actually it's not yet implemented. See:

  • https://jira.mongodb.org/browse/PYTHON-414
  • https://jira.mongodb.org/browse/PYTHON-419

目前,您必须自己处理这种情况.

For now, you have to handle this situation by yourself.

希望有帮助.

这篇关于Python中的Mongodb批量插入限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆