Is there a way to update a document when date is expired in mongodb?
问题 I have read some solutions and wonder if I can update (not delete) a document in mongodb if the date is expired after 2 days. Like this. date:2019-02-15 status:not expired After 2 days update the status into expired . Here is my code for posting a document. var bloodstock = new Bloodstock(); bloodstock.date = new Date(); bloodstock.status = "not expired"; bloodstock.save(function(err) {}); 回答1: Run a cron at daily midnight to compare the date. If the date exists 2 days update the status on