Sometimes gives json array empty or sometimes gives json array with values

#1

const locat = new ReactiveVar(Tests.find().fetch());
console.log(Tests.find().fetch());
export default locat;
Template.body.onCreated(function(){
console.log('on created ', this);
this.autorun(()=>{
var findCollection = Tests.find().fetch();
locat.set(findCollection);
})
})
this.locat = locat;

#2

Probably because you’re not waiting for the subscription to be ready? So the server hasn’t sent you the data yet.

#3

in what way i can do it ?

#4

You can use the ready callback of the subscription:


If you subscribe via a Template, you can also use the subscriptionsReady helper: