Difference between remoteDB.open("coll") and new Mongo.Collectoin("coll", { _driver: remoteDB} )


#1

In my app I have to connect to multiple DBS ( there is no limit to these DB’s there might be 100 of DB’s we need to connect)

We save all the mongo uri is our main db.

Here I want to open a connection to remote DB and need to perform around 10 queries on different collections

there are 2 ways to do it

first step is common for both ways

var database = new MongoInternals.RemoteCollectionDriver(dbURI);

then we can use either of the following two options

database.open('coll').findOne({ _id: id });

or

myColl = new Mongo.Collection( 'coll', { _driver: database } )

what is the difference between these two.

NOTE: I don’t need to listen to changes from these DB’s I just want to connect to these DB’s and perform some queries and close the connection.

For my requirement what is the best way?

I though when I’m using this database.open('coll').findOne({ _id: id }); I’m opening the connection to DB, so everytime when I query, I’m opening connection then querying, so definetly there is some delay there.

Am I correct there?

EDIT

If I use this method

myColl = new Mongo.Collection( 'coll', { _driver: database } )

my response time is faster

but I don’t want to keep on listening to changes to this colletion( I heard there is no oplog for this type collection but it will do polling to listen to changes)

Is there any way to close the connection so my app will not listen to changes?


#2

Not too sure about your primary question here, but you can pass an options object to configure Oplog on the remote driver:

var database = new MongoInternals.RemoteCollectionDriver(dbURI, { oplogUrl: 'mongodb://'})