Reactive publishing without parameters

Skip to first unread message

Slobodan Blazeski

Feb 25, 2015, 9:03:42 AM2/25/15
I have a constant array (issues)  which subset I want to  publish.
Currently I'm doing something like below:

Issues= new Mongo.Collection("issues"); // Created just for the cursor, would prefer simple array

     var simulation = Simulations.findOne({userId: this.userId}, {reactive:true});
      return Issues.find({date:{$lte:}});      

Since data contained in the issues is const, and I don't want to use parameters as described in
the filtering information must come exclusively from the server.

Is there any way to avoid reactive publish and if possible creating unnecessary mongo collection ?


Jeremy Hall

Feb 25, 2015, 10:19:39 PM2/25/15
Could you please explain why you don't want to use parameters passed from the client? That Stack Overflow post is either out of date, or very misleading. If you are subscribing to your collection on the client from a code block that is reactive (such as a Tracker.autorun, or an ironrouter's controller functions such as waitOn or subscriptions), and the parameter you are passing into the subscription changes based on some reactive dependency, then the client's subscription will be updated based on the filter you've set in the data publication.

Slobodan Blazeski

Feb 26, 2015, 1:59:36 AM2/26/15
I don't want to send it from the client due to security reasons. Basically that parameter controls how far the user has progressed in the simulation, if they could send arbitrary date they'll be able to time travel in the future.

Slobodan Blazeski

Feb 28, 2015, 2:15:36 PM2/28/15
I've solved my problem without reactive join, though solution seems like a hack.
I'm observingChanges to the collection the serves as my filter, but I'm using the low level mechanism 
to return data from my list.
Notice the ugly self.maxBookYear. I don't know how to access Subscription documents to see that latest year.

// Client 
Books = new Meteor.Collection('books');

// Server
Observations = new Meteor.Collection('observations');

var year = 1999;

Meteor.startup(function () {
year: year
// Some very interesting books
var books = [
{title: 'Book 1', year: 1999},
{title: 'Book 2', year: 2000},
{title: 'Book 3', year: 2001},
{title: 'Book 4', year: 2002},
{title: 'Book 5', year: 2003},
{title: 'Book 6', year: 2004},
{title: 'Book 7', year: 2005},
{title: 'Book 8', year: 2006},
{title: 'Book 9', year: 2007}

Meteor.publish('books', function () {
var self = this;
var initializing = true;

var handle = Observations.find({}, {sort: {year: -1}, limit: 1}).observeChanges({
added: function (id, fields) {
if (!initializing) {
var addBooks = _.filter(books,function(book){
return self.maxBookYear < book.year && book.year <= fields.year;
self.maxBookYear = fields.year > self.maxBookYear ? fields.year : self.maxBookYear;
_.each(addBooks, function (book) {
var id=;
self.added('books', id, book);
initializing = false;
self.maxBookYear = year;
self.added("books",, {title: 'Book 0', year: year});

Meteor.setInterval(function () {
year: ++year
}, 10000);
Reply all
Reply to author
0 new messages