Have any package to get data from "Publish" directly?

I want to get data from Publish or alternative directly

// Severe 
Meteor.pubAlternative('myPub', function (parameters ){
   var data = [];
   // do something
   ..........
   return  data;
});

// Client 
// Check pub is ready and then
.......
var getData = Meteor. subAlternative();

You can publish collection which will consist of documents describing where to subscribe and on client react to changes in that 1 collection.
If you really have to react on such events thrown by server.

I don’t understand, please example.

If you want chunk of data on demand, create REST API and access that.
If you want collections, with pub/sub use these.

My purpos, I want to generate report on server and pass data to client.

If your report doesn’t change over time just use a method to send your data. If it changes over time you can do something like this.
On client:

Reports = new Mongo.Collection('reports_sub');

Tracker.autorun(function () {
  Meteor.subscribe('reports_sub', {});
});

Tracker.autorun(function () {
  console.log(Reports.findOne());
});

on server:

Meteor.publish('reports_sub', function (args) {
  var pub = this;
  var id = Random.id();
  var data = {};
  pub.added('reports', id, data);

  someEvent(function (data) {
    pub.changed('reports', id, data);
  });

  pub.ready();
});

Checkout http://docs.meteor.com/#/full/meteor_publish for further info. There is a good example there which publishes counts of a collection.

You need to use a Meteor “method”. See the doc here.

thanks, I will check docs for more detail.

Thanks for all helping.
Now, I tried, but it is difficult to understand (not reactive).

1 Like