Reputation: 11197
I have two applications to be deployed seperately, but partially sharing a database and users. I created a pretty simple method to connect.
Remote.connect = function (remoteUrl="http://localhost:3030") {
let remote = DDP.connect(remoteUrl);
Meteor.remote = remote;
Accounts.connection = remote;
Meteor.users = new Mongo.Collection('users', {
connection = remote
});
return remote;
}
Meteor.startup(function () {
Remote.connect(Meteor.settings.public.REMOTE_URL);
});
So this will work -- I can log in as a "remote" user just as easily. However, I am having some trouble using other collections. For example:
Orders = new Mongo.Collection('orders', {
connection: Meteor.remote
});
This shares the same name as my "orders" collection on the remote application. I try to query it on my local but it does not yield any results. If I query it on the main application, it yields one result.
How can I connect to remote collections with meteor?
Upvotes: 0
Views: 548
Reputation: 4820
For your "client" app's collection to be populated with your "server" app's collection data, you will need to subscribe to this app's publication. The object returned by DDP.connect()
can help you do just that. Say your original app publishes orders this way:
Meteor.publish('orders', function () {
return Orders.find();
});
Then all you need to do in order to populate your client app is:
Meteor.remote.subscribe('orders');
Upvotes: 1