Hey everyone!
I’ve got a collection
on server1
and I want to publish it’s count to server2
. I have been successful in getting documents from server1
to server2
as follows:
//server1
EmailCampaigns = new Mongo.Collection('emailCampaigns');
Meteor.publish("emailCampaigns", ()=>{return EmailCampaigns.find()})
//server2
emailConn = DDP.connect(Meteor.settings.public.emailUrl);
EmailCampaigns = new Mongo.Collection('emailCampaigns', {connection:emailConn);
I can publish from server1
to server2
with no issues as follows:
emailConn.subscribe("emailCampaigns");
All of this works as expected but I have a problem when I want to do anything inside the publication with this
.
When I call
//server2
emailConn.subscribe("messageCount", {});`
The following publication breaks:
//server1
Meteor.publish("messageCount", (query) =>{
const self = this;
check(query, Object);
let count = 0;
let initializing = true;
let handle = EmailCampaigns.find(query).observeChanges({
added: function (id) {
count++;
if (!initializing)
self.changed("counts", roomId, {count: count});
},
removed: function (id) {
count--;
self.changed("counts", roomId, {count: count});
}
});
initializing = false;
self.added("counts", query, {count: count});
self.ready();
self.onStop(function () {
handle.stop();
});
})
And I get the following Error:
Exception from sub messageCount id JdQHxRgpS7RKcJS8X TypeError: Object [object global] has no method 'added'
When subscribing to a publication on a different meteor server this
isn’t the same as this
when subscribing on the same server.
Maybe I’m doing something wrong? I haven’t been able to figure this out yet though and i was wondering if anyone has had a similar problem.