I’m evaluating a NodeJS package that wants to persist data in redis or MongoDB. The Mongo instantiation is like so :
acl = new acl(new acl.mongodbBackend(dbInstance, prefix));
So the dbInstance
would come from mongodb.connect(server_uri);
by means of a command like :
var mongodb = require('mongodb');
mongodb.connect("mongodb://127.0.0.1:27017/acltest", function(error, db) {
var mongoBackend = new acl.mongodbBackend(db, 'acl_');
});
Is there a way to supply the local mongoDb connection to a 3rd party node package?
Can you use process.env.MONGO_URL
?
Well that’s a fallback option, yeah.
But . . . how do I get an existing connection from Meteor?
MongoInternals.defaultRemoteCollectionDriver().mongo.db
I think. Possibly.
Even if that’s correct, you may get problems if the versions of the mongo drivers don’t line up.
Thanks Rob (@robfallows)
const db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
const mongoBackend = new acl.mongodbBackend(db, 'acl_');`
It works!
I don’t know about version conflicts. I’ll cross that bridge when I get to it.
1 Like