Categories
Development Heroku MongoDB

How to change a property in a MongoDB collection every Sunday at 00:01 Midnight in app that written under Node JS?

I have an app on Heroku that’s written in Node JS and uses Mongo DB as a database.

In Mongo I have a collection GamePlan that one of the properties is Status :

const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const GamePlanSchema = new Schema({

  LeadId: {
    type: String,
    required: true
  },
  PackageId: {
    type: String,
    required: true
  },


  Status: {           // This one needs to be changed every Sunday Midnight 00:01 to value "4"
    type: String,
    required: true
  },

  InsertDate: {
    type: Date,
    default: Date.now
  }
});

module.exports = GamePlan = mongoose.model(
  "gameplan",
  GamePlanSchema
);

I’m looking for some kind of a task that would work automatically and change all the relevant documents in GamePlan.

What would be the best approach to solve this ?

Leave a Reply

Your email address will not be published. Required fields are marked *