I have a node.js express app with MongoDB database and what I want is to be able to update the database based on time
Interval. For example
Increase a number field automatically every 7 days for each user based on an activation date set on each document.
Please how do I achieve this?
2
Answers
You can use cron jobs for that.
A cron job used for scheduling tasks to be executed sometime in the future at specific time interval.
Find out more here:
You will schedule a cron job that will run once in a day and you will add your code to be executed.
The What are Database Triggers? documentation indicates triggers, however it’s not clear if that available on the free Community Edition, or only on their hosted Atlas offering. If you can’t figure out a Mongo trigger solution, you would have to code a controller in Node.js based on
.setInterval
to fetch user creation date(s) then insert whatever update(s) you want on the user(s).