Mongodb bulk insert limit in Python

ⅰ亾dé卋堺 提交于 2019-12-22 08:29:31

问题


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.


回答1:


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

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

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

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.

Hope that helps.



来源:https://stackoverflow.com/questions/16753366/mongodb-bulk-insert-limit-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!