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");
if(Meteor.isServer){
Meteor.publish('newCollectionData', function(){
console.log(newColl.find().fetch());
return newColl.find();
});
}
Here is My client Code(file is in /client)
Meteor.subscribe("newCollectionData");
//console.log(newColl.find());
console.log(newColl.find().fetch());
var data= newColl.find().fetch();
console.log(data);
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?
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 () {
console.log(newColl.find().fetch());
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With