我正在使用 Compoundjs 并使用 jugglingdb 的 mongodb 适配器。我一直在通过执行以下操作在控制器中检索和重用本机 mongodb 客户端:
var db = compound.orm._schemas[0].client;
这很好用,因为我可以使用 mongodb 支持的功能,例如,.collection(name)
除此之外.find()
。但是,当我为 Compoundjs 创建一个初始化程序时,.client
它是空的,但看起来_schemas[0]
不是。例如:
module.exports = function (compound) {
var db = compound.orm._schemas[0].client; // _schemas[0] isn't empty as .client was reached.
db.collection('collection'); // Throws: TypeError: Cannot call method 'collection' of undefined
};
如何从 jugglingdb 适配器检索本机 mongodb 客户端,而无需自己重新创建连接?