Unable to display data on a page


Comments = new Mongo.Collection('comments');

if (Meteor.isClient) {
  Meteor.subscribe('allComments');


  Template.courses.helpers({
    course: function () {
      return Comments.find({});
    }
  });

}


if (Meteor.isServer) {
  Meteor.publish('allComments', function () {
    if (this.userId)
      return Comments.find({});
    else
      return this.ready();
  });
}

template

<template name = "courses">
		<br>
		<br>
		{{#each course}}
		<h1>{{name}}</h1>	
		{{/each}}
</template>

Template.courses.helpers({
    course: function () {
      return Comments.find({}).fetch();
    }
  });

There’s your problem. find() returns only a cursor (i.e. something that only points at the result set), not the actual results themselves. You then either need to fetch() the data from the set as is, you could map or forEach over the results or simply observe the result set for changes.

No, i don’t think its working, i tried out but still the same

do you think there’s a problem with the template ?? @rhywden

No cursors are fine to return from the helper. In Blaze it is actually the preferred way to pass data to the template, where #each iterates over the cursor for you.

@madguy02 This looks fine to me.
Have you double checked that there’s data in the db?
Are you including the template in your page correctly?
Is there any other code that could be affecting this?

I think your problem is the publish function. Are you logged in?
If you are not logged in the “this.userId” will return “null” and the function will return this.ready() every time.

2 Likes