node.js - 如何在每个星期日午夜 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
.
解决这个问题的最佳方法是什么?
解决方案
如果你只想使用 nodejs 来做,你可以看看下面的 pacakge - https://www.npmjs.com/package/node-cron
如果你想让 Heroku 处理它,你可以点击这个链接 -在 Heroku 上运行 Cron 任务
推荐阅读
- java - 了解 CopyOnWriteArrayList 中的快照
- java - 如何避免从 JPA 实体中保存截断的数据
- discrete-mathematics - 使用双射规则计算具有偶校验的二进制字符串
- amazon-web-services - CloudWatch 到 SNS:如何为 SNS 订阅过滤设置消息属性?
- azure - 在 Azure 中调试 asp .NET Core 5 beta
- android - 离线 Android Gradle 插件
- android - 在 Android 上的 Kotlin 中,如何在一个或每个循环期间在不可变列表中发生空指针异常?
- mysql - Mysql 按速度排序
- python - 使用 python 执行命令行脚本时找不到“__main__”模块
- java - Spring Webflux - 抛出检查的自定义异常(不是 RuntimeException)的正确方法