I’m trying to connect two meteor apps (server-side), and I’m quite happy with DDP.connect
. However, the subscribe
function never calls the onReady
callback, nor does the ready()
function of the returned subscription ever become true
. Am I doing something wrong?
Here is a minimal code snippet to illustrate the problem. It assumes another meteor app running on port 3000 with a published items collection:
const a = DDP.connect("http://localhost:3000");
var aItems = new Mongo.Collection('items', a);
const sub = a.subscribe("items", function() {
console.log("ready");
// this is never called!
});
// also:
Meteor.setTimeout(function() {
sub.ready(); // this remains false
}, 10000);
Am I doing something wrong?
May be
var aItems = new Mongo.Collection('items', {connection: a});
And guess your server-side collection also should be named items
To clarify: the connection and even the subscription works just fine. I get all the documents from the remote collection and can also write to it (insert/update/remove). I just never get the ready message, even though I can tell that it is fully synced.
1 Like
Ah, I see. But doesnt this would trigger?
const sub = a.subscribe("items");
Tracker.autorun(() => {
console.log(sub.ready());
});
No, unfortunately sub.ready()
remains false no matter how long I wait.
You may also look at a.connection._subscriptions
. So there should be your sub with ready state. I guess if it doesnt handled you should report a bug on GH.
Regards!
I found my problem. I got myself confused by having an (incorrect) publish function while autopublish was still active. The publish function didn’t work, but since I still received data on the other end (due to autopublish) I was looking for the problem elsewhere.
Sorry for the false alarm and thanks for trying to help, @mrzafod! I appreciate it.