Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Meteor JS : Client not getting data from Mongo DB

I have started learning MeteorJS and made a sample app. I have a collection in mongoDB and I am trying to see that collection in client Here is my server Code(file is in /libs)

newColl=new Meteor.Collection("newColl");
  Meteor.publish('newCollectionData', function(){
    return newColl.find();

Here is My client Code(file is in /client)

var data= newColl.find().fetch();

The log in server prints the data correctly but the log on client prints an empty array. PS: I have removed auto publish, but with it also it was giving same result. Where am I going Wrong?

like image 824
user1551574 Avatar asked Feb 12 '23 20:02


1 Answers

Cursor.fetch() returns immediately with data currently available. If no data are available on the client in the time of call, it returns nothing.

It is reactive source, so just try to call it in Tracker.autorun and it will be recomputed when the reactive source changes.

Tracker.autorun(function () {
like image 137
Krab Avatar answered Feb 14 '23 10:02