Lazy connection
From the mailing list:
Hi All,
I am running django + mongo. So I have connect() call in the settings.py. However, if mongodb is down (yeah, it may happen with dev setup), the webapps are totally unavailable. A large portion of our site doesn't require mongodb to run. Is there a way to config mongoengine do lazy connection?
For example, call lazy_connect() with parameter, and don't connect to db until necessary.Thanks & enjoy weekend! Frank
This connect() call in settings.py is a PITA. Is there an intention to replace it with a standard settings dict?
+1, I need to launch my web application just to re-generate static assets and it requires MongoDB only because it connects non-lazily.
Any workarounds available?
Found it! Instead of:
mongoengine.connect(**conn_settings)
...it is possible to write:
mongoengine.register_connection(
mongoengine.DEFAULT_CONNECTION_NAME,
conn_settings.pop('db', None),
**conn_settings
)
...which then results in lazy connecting.