0

I want to connect to different databses and get data from the same collection. ex collection name is groups

I'm using

var database = new MongoInternals.RemoteCollectionDriver(dbURI);

to initalize remote db connection and

then using

var Groups = new Mongo.Collection('groups', { _driver: database });

after doing this meteor registers methods groups/insert groups/update and groups/removed to my collection

enter image description here

this is working fine for first db, when I try to connect to the second db it is throwing error saying

Error: A method named '/groups/insert' is already defined

from the error I get it that I'm initializing same collection again but with different db and meteor is trying to register method and it fails

so here I want to de-register my collection from app so meteor will remove grousp/insert methods from the app and then when I try to initialize it again it works fine.

any help appreaciated.

NOTE

I can do this also

database.open('groups').findOne({ displayName: 'group1'});

but opening the db for each and every query is taking time so response is time is more.

If any one knows other ways to do this please answer ( using node mongodb driver maybe??)

EDIT

NOTE: I don't need to listen to the changes of remote collection, I just want to connect to them and perform few queries and close the connection.

Sasikanth
  • 3,045
  • 1
  • 22
  • 45
  • This is pretty similar to [this question](https://stackoverflow.com/questions/33464238/meteor-connect-collections-of-multiple-databases). Can you take my first suggestion and create multiple collections instances (`groupsDB1`, `groupsDB2`, etc.)? Querying them will be a little awkward, but at least you wouldn't have to open and close them continually. – David Weldon Nov 08 '15 at 17:15
  • @DavidWeldon, Thanks for the response, I'll have so many databses ( we're in school business and each school has their own databse), here I'm writing API, from your first suggestion I can't declare so many collections and also connections should be dynamic. – Sasikanth Nov 08 '15 at 17:42
  • @DavidWeldon, am I correct or your solution works for my usecase? If so am I missing anything here? I really appreacite your response. – Sasikanth Nov 08 '15 at 17:43
  • This is a bit of a tangent, but could you use something like [partitioner](https://github.com/mizzao/meteor-partitioner) to separate your data, rather than having separate databases? It seems like you are setting yourself up for a difficult situation. – David Weldon Nov 08 '15 at 17:48
  • @DavidWeldon thanks for the response I will look into it and get back to you. – Sasikanth Nov 08 '15 at 17:57

0 Answers0