I have the code
datas = new Meteor.Collection("datas")
var data = datas.findOne('101abcde1f2345ac00000001')
if (Meteor.is_client) {
Meteor.startup(function () {
console.log(data.name)
});
}
But what I get in the console is an undefined error. However if I type console.log(data.name) into the web inspector’s javascript console (presumably after some kind of wait it works. I’m already putting the code in Meteor.startup to ensure that the DOM is ready. what could I be doing wrong?
It seems that you are using
autopublishpackage. And (of course),Meteor.startupdoesn’t wait subscription completed.Usually, we use reactive context & data to do this in Meteor –
Anytime
datascollection has changes(?), the function inMeteor.autosubscribewill be called.