首页 > 解决方案 > 如何在每个星期日午夜 00:01 在 Node JS 下编写的应用程序中更改 MongoDB 集合中的属性?

问题描述

我在 Heroku 上有一个用 Node JS 编写的应用程序,并使用 Mongo DB 作为数据库。

在 Mongo 我有一个集合 GamePlan ,其中一个属性是 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
);

我正在寻找某种可以自动工作并更改GamePlan.

解决这个问题的最佳方法是什么?

标签: node.jsmongodbherokumongoose

解决方案


如果你只想使用 nodejs 来做,你可以看看下面的 pacakge - https://www.npmjs.com/package/node-cron

如果你想让 Heroku 处理它,你可以点击这个链接 -在 Heroku 上运行 Cron 任务


推荐阅读