Meteor publish subscribe wrong output

305 views Asked by At

im new to Nodejs / Meteor and Mongodb. im having this problem which i cannot get my data when i try to use publish and subscribe in meteor

lib/collection.js

Reports = new Meteor.Collection('reports'); 

lib/routes.js

Router.map(function() {
  this.route('dashboard', {
    path: '/dashboard',
    waitOn: function () {
      return Meteor.subscribe('reports-limit', {limit: 5});
    },
    data: {
      title:'Dashboard',
      reports: function(){
        console.log(Reports.find({}));
        return Reports.find({});
      }
    },
    action: function () {
      if (this.ready()) {
        this.render();
      }
    }
  }); //end this.route
});//end Router map

server/publisher.js

Meteor.publish('reports-limit', function(option){
  var limit = options.limit;
  return Meteor.reports.find({}, {sort: {date: -1}, limit: limit});
});

client/template/dashboard.html

<Template name="dashboard">
  <div class="content">
    {{title}}
    <ul>
      {{#each reports}}
        <li>{{_id}}</li>
      {{/each}}
    </ul>
  </div>
</Template>

I don't get any display in the id and the console.log() is giving me

L…n.Cursor {collection: LocalCollection, sorter: null, _selectorId: undefined, matcher: M…o.Matcher, skip: undefined…} 

as a result

this is the packages i installed

$ meteor list
accounts-facebook                     1.0.4  Login service for Facebook accounts
bootstrap                             1.0.1  Front-end framework from Twitter
iron:router                           1.0.9  Routing specifically designed for Meteor
meteor-platform                       1.2.2  Include a standard set of Meteor packages in your app
monbro:mongodb-mapreduce-aggregation  1.0.1  Expose mongodb aggregation framework (mapReduce, aggregate and distinct), to SERVER si...
service-configuration                 1.0.4  Manage the configuration for third-party services

i'm not sure what i've been missing and what i've done wrong.

1

There are 1 answers

0
Jeremy S. On

Once you name a collection with a global variable, e.g. Reports = new Meteor.Collection('reports');, you should use that global to access the collection both server and client side.

So return Meteor.reports.find(); in your publication is wrong. It should read:

return Reports.find();

The rest of the query looks ok.