2👍
✅
you have a race condition, i’d call it. you don’t show where you have your subscribe, i assume it’s in the onCreated(). if so, yes, there is no guarantee that the data will be ready when you do your find.
the typical solution is to wrap your find in an autorun, like this:
this.autorun(function() {
var user = ProfessionalOverview.findOne({"candidateUserId": id});
if (user) {
// rest of the code that uses this data
}
});
You can also use collection isReady Callback for same
this.autorun(function() {
if (ProfessionalOverview.isReady()) {
var user = ProfessionalOverview.findOne({"candidateUserId": id});
// rest of the code that uses this data
}
});
by protecting it with the “if”, you won’t bother doing any work until the data shows up.
Source:stackexchange.com