Watch document value on db to update another value


#1

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.


#2

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()


#3

Yeap, that worked for me. Thanks!