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) {
  Data = new Mongo.Collection("myData");

if (Meteor.isServer) {
  var database = new MongoInternals.RemoteCollectionDriver("mongodb://");
  Data = new Mongo.Collection("myData", { _driver: database });

  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?


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?