Collection set using RemoteCollectionDriver has no data in the Client

Trying to use a remote mongodb hosted in MongoLab. My code to do that below:


if (Meteor.isClient) {
  Meteor.subscribe('allData')
  Data = new Mongo.Collection("myData");
  console.log(Data.find().count());
}

if (Meteor.isServer) {
  var database = new MongoInternals.RemoteCollectionDriver("mongodb://username:password@xxx.mongolab.com:00000/db");
  Data = new Mongo.Collection("myData", { _driver: database });
  console.log(Data.find().count());

  Meteor.publish('allData', function () {
    return Data.find();
  })
}

The server code seems to work since the console logs out the correct .count(), but the client only logs 0 for the .count(). Will using a remote mongodb only work on the server, and won’t be accessible in the client code?

Thanks!

You’ve instantiated your Data collection on the server only.

Normally, it’s just a case of declaring the Data = new Mongo.Collection() in a shared folder (like lib/), but I actually don’t know what will happen in this case, as the _driver option is an internal property. The collection.js code indicates that it will work correctly on the client. So …

try it and let us know! :smile:

@robfallows - I’ve declared Data on both client and server (you may have missed the code inside isClient), although I will try setting it inside shared code.

Ah, oops, yes - I did miss that!

Hi! You solved this problem?