Remote data subscription returning empty

I’m having an issue where I want to remotely subscribe to data that belongs to another meteor app (using DDP.connect) unfortunately I don’t receive any data from the user’s collection. The idea is to get whether a given user is connected to the app I want to fetch data from, for that, I’m using the user-status package.

const Remote = DDP.connect(remoteUrl);
const RemoteUsers = new Mongo.Collection('remoteUsers', Remote);
const remoteSub = Remote.subscribe('users.online');

// despite the remote sub returns an unique id
RemoteUsers.find({}).fetch() // returns []

Any ideas as to why I can remotely subscribe to any publication except the users collection?

Thanks in advance

A long time ago (Meteor@1.0.x) I experimented with this and found out that the Accounts package uses its own connection. Back then I got it to work with something like this on the client, and this still works …

Meteor.remoteConnection = DDP.connect( RemoteDataUrl );
Meteor.remoteConnection.onReconnect = function() {
  console.info('Meteor.remoteConnection.onReconnect');
}
Accounts.connection = Meteor.remoteConnection;
Accounts.users = new Meteor.Collection('users',{connection: Meteor.remoteConnection});
Meteor.users = Accounts.users;
// use any other collection from the remote server
Categories = new Meteor.Collection('categories',{connection: Meteor.remoteConnection});

The biggest problem I encountered is that the Meteor bootstrap process sets Accounts.connection to the actual server where the code comes from, so when the above code runs there already has been made a connection, which results in the localStorage('Meteor.loginToken') to be invalid, so every reload you get logged out.

According to the docs it should be possible to do new AccountsClient({connection: Meteor.remoteConnection}) or even new AccountsClient({ddpUrl: remoteUrl}), but I dodn not get that to work.

The real solution would be to figure out how to prevent/override the Accounts = new AccountsClient() in accounts-base/client_main.js

1 Like

Thanks for the info!
In the meantime I implemented a Meteor method that gives me the data I need, the idea was to create a reactive select component that will update as users go online/offline so the final user would never had the chance to pick someone who is not online.
I guess I will have to re-trigger the method to fetch the online users every some interval of time

Thank god for open-source. I actually figured out how it’s supposed to be done for Accounts that it works 100%, with reload and everything. Super easy, just not documented anywhere (I was able to find) … :angry:

On the server of your application do this

Meteor.startup(() => {
  // code to run on server at startup
  __meteor_runtime_config__.ACCOUNTS_CONNECTION_URL = remoteUrl;
})

For any other collection you can follow the code

Meteor.remoteConnection = DDP.connect( RemoteDataUrl );
Categories = new Meteor.Collection('categories',{connection: Meteor.remoteConnection});

and it will be reactive