skip to Main Content

For Example: On the 1st of August 2022 at 12:00 AM the variable should increase by 1.
The variable is stored in MongoDB, this is for a mern stack project.
How should I go about this?

2

Answers


  1. I would suggest to use some cron jobs, which can update what you want in given time.
    e.g. package: https://www.npmjs.com/package/node-cron

    Set it to 0 12 1 * * which represents invoking your function 12:00 AM every first day of month

    Login or Signup to reply.
  2. I wouldn’t increase the value by one on the first of each month. I instead would use a field containing the startDate as a reference and use that one to calculate the number of months between the startDate and the current date.

    You can use that compute result directly or store it in an additional field.

    You actually always need to use a reference date. Even if you increment it every month because you need to check if your increment script was actually executed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search