This can be accomplished by using the connected
event from the JugglingDB event emitter.
module.exports = function (compound) {
compound.orm._schemas[0].once('connected', function () {
var db = compound.orm._schemas[0].client;
db.collection('Module');
});
};
Explanation:
When JugglingDB loads an adapter, it passes in a finished callback, which triggers the connected event. When loading the mongo adapter, the adapter uses an async call to connect to the database, which could cause initializers to run before the adapter is fully connected.