Is it possible for a MongoDB connection to timeout in Python?
heroku, mongodb, python
Solution
Citing from Pymongo documentation: https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient
The client object is thread-safe and has connection-pooling built in. If an operation fails because of a network error, ConnectionFailure is raised and the client reconnects in the background. Application code should handle this exception (recognizing that the operation failed) and then continue to execute.
So as @james-wahlin suggested in comments, you should not solely rely on pymongo's connection-pooling mechanism but always wrap your usage of `self.db` in `try..except` clauses.
Hope this helps.
Problem
(Newbie question, sorry about that -I'm just beginning with MongoDB) I am connecting to mongo on heroku like this: ``` self.connection = pymongo.Connection(MONGO_URL) self.db = self.connection.app13805318 ``` Is it possible that I try to use self.db after a few hours and can't read it? Do I need to do some kind of keepalive or refresh of the connection?