Blaine Lafreniere
Blaine Lafreniere

Reputation: 3600

Published documents not accessible from client side

Here's the server side code where I publish the documents:

function messageData () {
  var fiveHoursAgo = unixTimestampSeconds() - 5 * 60 * 60;
  return Messages.find({unixTimestamp: {$gte: fiveHoursAgo}});
}

function userData () {
  return Meteor.users.find({}, {fields: {'status.online': 1, username: 1}});
}

if (Meteor.isServer) {
  Meteor.publish("userData", userData);
  Meteor.publish("messageData", messageData);
  Meteor.startup(function () {
    // code to run on server at startup
  });

The subscribe call:

  Meteor.subscribe("userData", "messageData");

If I put a console.log(Messages.find({}).fetch()); in the scope of Meteor.isClient I see an empty array in my browser console.

If on the server side, I put in a console.log(messageData().fetch()) I see the two documents I have in my database.

What's also interesting is, when I add the package 'mongol' and look at the subscriptions it recognizes, this is what I see:

enter image description here

It looks to me as though the two subscriptions are somehow being kludged into one.

Upvotes: 1

Views: 27

Answers (1)

Ethaan
Ethaan

Reputation: 11376

Try with differents Subscribe.

if(Meteor.isClient){
  Meteor.subscribe("userData");
  Meteor.subscribe("messageData");
}

Upvotes: 2

Related Questions