You can create a MongoDB connection somewhere and import it, as opposed to calling pymongo.connection.Connection()
every time you need it. Or you can create a Singleton for this. Something like this in settings.py
.
class ConnectionSingleton(object): """Represents a MongoDB connection""" conn=None def __new__(cls,*args,**kwds): if cls.conn is None: cls.conn=pymongo.connection.Connection() return cls.conn
Won't this solve your problem?
source share