Jens Zastrow
Jens Zastrow

Reputation: 297

Meteor collection query with current timestamp

I need to schedule items which have an attribute 'scheduledAt with timestamps, both current and projected. Unfortunately the reference Date is only calculated once.

How can this be solved?

Items.find({scheduledAt : {$lt : new Date()}}).observe(...)

Upvotes: 2

Views: 680

Answers (1)

Dror
Dror

Reputation: 2410

Because Meteor is a single page app, "new Date()" is not going to get called unless you make it reactive by doing something like:

function findItems() { Session.get Items.find({scheduledAt : {$lt : new Date()}}).observe(...) }

And you can trigger by doing Session.set('triggerEvent');

If you just want to do it periodically, use Meteor.setTimeout()

Upvotes: 1

Related Questions