how to automatically insert data into MongoDB when time limit increase

Viewed 139

I am working on project where i want to automatically insert data when user doesn't input when time limit increase, for example when it is 12AM of a day then it automatically insert a data which can be

{
"_id": "611570ac944a3335483fcc04",
      "username": "abc",
      "Date": "2021-08-14",
      "attendance": "absent",
}

please help how to do this

1 Answers

We can achieve this by Cron. It is a tool that allows to execute something on a schedule. Cron Npm

var CronJob = require('cron').CronJob;
var job = new CronJob('00 00 00 * * *', function() { //execute at every midnight
  //Add your condition 
});
job.start();
Related