I am writing a python code to update each document in collection. My code is like:
for r, d_50 in enumerate(grid50.find().batch_size(500)):
self_grid = grid50.find({'_id':d_50['_id']})
.....
.....
(processing process)
grid50.update({'_id':d_50['_id']},{'$set':{u'big_cell8':{"POI":venue_count, "cell_ids":cell_ids}}})
However, when I run this code, I met problem:
raise AutoReconnect(str(e))
pymongo.errors.AutoReconnect: connection closed
Does anyone know how to deal with this problem? Should I add something in my code to deal with this?
From PyMongo Docs -
exception pymongo.errors.AutoReconnect(message='', errors=None)
Raised when a connection to the database is lost and an attempt to auto-reconnect will be made.
In order to auto-reconnect you must handle this exception, recognizing that the operation which caused it has not necessarily succeeded. Future operations will attempt to open a new connection to the database (and will continue to raise this exception until the first successful connection is made).
Basically you'll have to handle this exception so that the application reconnects to mongo and re-runs the function that failed..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With