gamechanger/mongothon — pull request #43 by thieman (2014-12-10 20:25:40+00:00)
Title: Add offline model creation capability

Currently, Mongothon requires an existing connection to Mongo
to create new models. It is usually desirable to have models available
for import at the module level, so this pattern requires instantiating
a Mongo connection at module import.

This creates a deploy-time dependency on Mongo for your app to start up.
This is risky as a short-lived inability to connect to Mongo could take
down your app completely. It would be preferred if an app would be able
to start up, error while Mongo is down, and start functioning normally
once the Mongo connection is restored.

This commit adds a `create_model_offline` function to supplement the existing
`create_model`. Instead of passing a fully fledged PyMongo collection,
which requires a database connection upon instantiation, you can instead
pass a function to `create_model_offline`. The Model implementation will
resolve that function when it first needs to actually access Mongo.

This should go a long ways towards minimizing the deploy-time risk described.

@tleach