0
I am making a prototype in Meteor that will need to connect to multiple databases and need to export to each of the databases a same Nucleon and I am not able to do the Publish of the Nucleons with different names to differentiate.
The idea is, I have several databases and in all there is Collection users, I need to do the Publish of 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 there is data in both databases, the data on the client side of the Collections are empty.
What would be the correct way to do Publish and subscribe in that case?
I have tried the approaches present in the answers to the questions:
- How can i Publish the same Collection under Different Names in a Meteor app?
- Publishing/subscribing Multiple subsets of the same server Collection
- Meteor Publish/subscribe Strategies for Unique client-side Collections
But all resulted in empty customer side Customers.
Good Alex, try to do
return
of the cursor inside theMeteor.publish
– Gonsalo Sousa