1

I have a collection of objects with a date/timestamp property which designates when that item 'becomes active' and visible to the user. The items shouldn't be visible to the user until the time passes a certain point and the query condition holds true.

Example

My publish function on the server looks something like this:

Meteor.publish('publishName', function() {
    return MyCollection.find({activeFrom: {$lte: new Date()}});
});

When I load the page at 22nd November at 15:45, and an item in the collection has the activeFrom property set to the 22nd of November, 15:50, I would like my publish method to automatically push that item to the client when the clock becomes 15:50.

I haven't been able to find any tips on how to achieve that. Surely someone must have done something like this with Meteor before?

alexanbj
  • 66
  • 5
  • How did you set value to **activeFrom** ? – SG_ Nov 22 '14 at 16:22
  • @SG_ the administrators of the site set it when creating new items, it is usually set to some time in the future. – alexanbj Nov 22 '14 at 16:50
  • Publish functions are not reactive so doing what you want on the server requires an observe handler which will be tricky to write. If the collection is small, a much easier solution is to publish it without the activeFrom restriction. Then on the client you can reactively update the UI as needed. One of us can show that code if this is an acceptable solution. – David Weldon Nov 22 '14 at 17:29
  • Yeah, for now I can probably work around it by publishing the entire collection, then filtering on the activeFrom property on the client side using Tracker and setInterval for reactivity so the items appears as time passes (date.now() > activeFrom). I would like to fix it properly though, I don't mind writing a custom observer handler. – alexanbj Nov 22 '14 at 19:01

0 Answers0