skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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).

    Types of Database Triggers MongoDB provides three types of triggers:

    • Database Triggers: Perform some type of action when a document is updated, added, or removed.
    • Scheduled Triggers: Scheduled actions that occur at a specific time or set interval. MongoDB Atlas leverages an intuitive approach to
      scheduling triggers using the CRON expression language. These types of
      triggers can be as simple as running a daily clean-up process of
      temporary records, to generate a minute-by-minute report on
      transaction anomalies.
    • Authentication Triggers (Realm only): Actions that happen when creating or deleting a user or on login into MongoDB. These types of
      triggers are for performing user maintenance or user audit tracking
      for Realm apps.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search