Watch document value on db to update another value

Hi, I have a collection like this one:

Events = new Meteor.Collection('events');
Events.attachSchema(new SimpleSchema({
  start: {
    type: Date,
    defaultValue: new Date()
  },
 started: {
    type: Boolean,
    defaultValue: false
  }
}));

What I want to achieve is to update started attribute once the start date has been reached.
The question here is how to check this start date variable to see if has been reached?

What I have until now is a interval in the client to check if this dates has been reached once the user enter to a specific event view.

You can schedule periodic check using for example https://github.com/percolatestudio/meteor-synced-cron which will run update query on Events collection.

Events.find({
  start: {
    $lte: new Date()
  },{
    $set: {
      started: true
    }
  }
});

Bonus answer:
You can do that with any moment in time, not only current with momentjs package with moment().toDate()

1 Like

Yeap, that worked for me. Thanks!