node.js - How do I get the native mongodb client from a jugglingdb adapter during compoundjs initialization? -
I am working with compoundjs and using jugglingdb's mongodb adapter. I am retrieving and reusing by doing the following tasks in the controller:
var db = compound.orm._schemas [0] .client; This works great, because I'm able to use the function, such as .collection (name)
and .find () < / Code> However at the top of it, when I create the compound for the initiator, the .client
is empty, but it seems that _schemas [0]
is not an example For:
module.exports = function (compound) {var db = compound.orm._schemas [0] .client; // _schemas [0] is not as empty. Db.collection ('archive'); // throws: type error: method can call 'archive' not undefined};
How can I retrieve native mogul clients from juggling db adapter, to rebuild the connection?
This JugglingDB event can be completed by using the emitter using the connect
event is.
module.exports = function (compound) {compound.orm._schemas [0] .once ('connect', function () {var db = compound.orm._schemas [0] client ; Db.collection ('module');}); }; Explanation: When JugglingDB loads an adapter, it passes through a full callback, while using the one to connect the adapter database while loading the Mongo adapter , Which can be helpful in running the initializer before the adapter is fully connected.
Comments
Post a Comment