Mongo collections with the same name in different databases

0

I am doing a prototype in Meteor that will need to connect to several databases and need to export to the same database the same collection and I am not able to publish the collections with different names to differentiate.

The idea is, I have several databases and in all there is the collection users, I need to publish them all, each with a name.

Server-side

// Usuários do banco de dados 1
var RemoteDatabase1 = new MongoInternals.RemoteCollectionDriver(dababaseUrl1);
var Users1 = new Mongo.Collection('users', { _driver: RemoteDatabase1, _suppressSameNameError: true });

Meteor.publish('users1', function() {
  var UserCursor1 = Users1.find({});

  // this automatically observes the cursor for changes,
  // publishes added/changed/removed messages to the 'people' collection,
  // and stops the observer when the subscription stops
  Mongo.Collection._publishCursor(UserCursor1, this, 'users1');

  this.ready();
});

// Usuários do banco de dados 2
var RemoteDatabase2 = new MongoInternals.RemoteCollectionDriver(dababaseUrl2);
var Users2 = new Mongo.Collection('users', { _driver: RemoteDatabase2, _suppressSameNameError: true });

Meteor.publish('users2', function() {
  var UserCursor2 = Users2.find({});

  // this automatically observes the cursor for changes,
  // publishes added/changed/removed messages to the 'people' collection,
  // and stops the observer when the subscription stops
  Mongo.Collection._publishCursor(UserCursor2, this, 'users2');

  this.ready();
});

Client side

// Usuários do banco de dados 1
const Users1 = new Mongo.Collection('users1');
Meteor.subscribe('users1');

var Users1Values = Users1.find({});
console.log(Users1Values);
Users1Values.forEach((user1Value) => {
  console.log(user1Value);
});

// Usuários do banco de dados 2
const Users2 = new Mongo.Collection('users2');
Meteor.subscribe('users2');

var Users2Values = Users2.find({});
console.log(Users2Values);
Users2Values.forEach((user2Value) => {
  console.log(user2Value);
});

The problem is that even though data exists in both databases, the client-side data collections are empty.

What would be the correct way to publish and subscribe in this case?

I have tried the approaches present in the answers to the questions:

But all resulted in empty collections on the client side.

    
asked by anonymous 22.10.2018 / 05:04

0 answers