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

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;

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

in what way i can do it ?

You can use the ready callback of the subscription:


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