How to get/return data form subscribe callback?


#1

I would like to get/return data form subscribe callback like this

// in client/
var count;
Meteor.subscribe('posts', function() {
  count = Posts.find().count();
});

or -----------------------------------
var count = Meteor.subscribe('posts', function() {
  return Posts.find().count();
});

alert(count);

#2

This doc (second sample code) shows how to publish the size of a collection.


#3

I want to get data from subscribe callback?


#4

What kind of data are you tying to dig? The count of documents that you’ll get from subscription? Or just count of documents in a collection? Note that count() is a reactive data source. Please try to find out more about reactivity in Meteor!

Tracker.autorun(function() {
    console.log(Posts.find().count());
})