问题
I've looked at other solutions to this, such as:
- Mongodb: Connection reset by peer
- Mongodb : AutoReconnect, Connection reset by peer
But still have this error. I'm trying to load a large GeoJSON file into MongoDB.
Here's my code: https://gist.github.com/mittenchops/6499844
using the iterative json parser here: https://github.com/isagalaev/ijson
Here is my error:
Traceback (most recent call last):
File "upload2mongo.py", line 57, in <module>
main(sys.argv)
File "upload2mongo.py", line 52, in main
loader(renamesh2json(argv[1]), argv[2])
File "upload2mongo.py", line 22, in loader
db[collection].insert(d)
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 853, in _send_message
raise AutoReconnect(str(e))
pymongo.errors.AutoReconnect: [Errno 104] Connection reset by peer
Why am I receiving this strange error about my connection shutting down?
回答1:
Not sure if this is an answer or even makes sense, but I added one more loop in my insert sequence, and that corrected the problem. It seems that the original object I thought I was inserting was actually a list of documents instead of document-level, and this was implicitly batch-inserted---when I thought I was actually inserting one document at a time, I thought I was already looping at the document level.
It appears that over the course of the batch insert, the connection closed.
来源:https://stackoverflow.com/questions/18705007/mongodb-connection-reset-by-peer