Title: Meteor re-activity issue inside template helper
Tags: meteor
Question: I currently have a template where I am querying the database with the following query.

```allMessages = Messages.find({$or: [{type: "user_message"}, {type: "system_message", time: {$gt: (Date.now() - 180000)} }]}, {sort: {time: 1 }}).fetch()
```

Now obviously the template helper gets re-run whenever something new goes into or is removed from this set of data, which is exactly what I want. The issue arises when a ```system_message``` gets older than 2 minutes and I no longer want that message to by apart of my query. The data does not update when this happens, and only updates when a new message comes in or a for some reason a message is removed. 

Does anyone know why this might be the case? It seems to me that there shouldn't be an issue as the data on the query is changing so it should be re-running but it isn't.

Comment: The actual data inside the collection is not changing, thus the query is not being rerun, the way I get around this is to use a `Deps.dependancy` that uses a set timeout to fire a changed event.


Here is another answer: It isn't working because ```Date.now()``` isn't a reactive variable. If you were to set the date limit in something like a session variable or a ReactiveDict, it would cause your helper to recompute. Here's an example using the ```Session```:

```Template.myTemplate.allMessages = function() {
  var oldestMessageDate = Session.get('oldestMessageDate');
  var selector = {
    $or: [
      {type: "user_message"},
      {type: "system_message", time: {$gt: oldestMessageDate}}
    ]
  };
  return Messages.find(selector, {sort: {time: 1}});
};

Template.myTemplate.created = function() {
  this.intervalId = Meteor.setInterval(function() {
    Session.set('oldestMessageDate', new Date - 120000);
  }, 1000);
};

Template.myTemplate.destroyed = function() {
  Meteor.clearInterval(this.intervalId);
};
```

Every second after the template is created, it changes ```oldestMessageDate``` to a new date which is two minutes in the past. Note that the ```intervalId``` is stored in the template instance and later cleaned up in the ```destroyed``` callback so it won't keep running after the template is no longer in use. Because ```oldestMessageDate``` is a reactive variable, it should cause your ```allMessages``` helper to continually rerun.

Comment for this answer: @SeanCallahan did this solution end up working for you?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:07/14/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<meteor>', 'Title': 'Meteor re-activity issue inside template helper', 'ViewCount': 44, 'id': 24739131, 'user_AboutMe': '', 'user_AccountId': 2322252.0, 'user_DisplayName': 'Scalahansolo', 'user_Reputation': 2375.0, 'user_Views': 279.0, 'user_id': 2037655.0}}