Meteor collection return array

I have some data i want to retrieve from one of my collections. The data i want to receive will not be printed out to the template but rather used internally in one of my functions somewhere.

This is the code


var mynumber = Session.get('number');
         
var my_friends = Kontacts.find({my_number: mynumber}).fetch();
console.log(my_friends);
for (i in my_friends)
{
  console.log(my_friends[i].contact_number);
}

This console.log(my_friends); returns an empty array.

I have subscribed and even published my collection. Is this the meteoric way of returning an array from a collecton?.

Did you wait for the subscription to be ready? If you subscribe and then immediately query, there hasn’t been enough time for the data to show up yet.

2 Likes

I am not sure whether the subscription is ready yet. I will check my code again. Thanks.