如果在一段时间后未修改文档,如何使函数自动滴答
How do I make a function tick atomically if the document is not modified after a certain period of time
您好,我正在使用 mongoose/mongodb 并拥有此数据结构
{
step: "Lorem",
status: "in-progress",
bool: true,
startedAt: Date.now(),
inactive: false
}
如果前三个属性在一定时间后没有变化,如何设置inactive
为true
感谢您的帮助!
你需要一个额外的字段updateAt
,每次step
或status
或bool
改变时,你也需要改变updateAt
。
您终于可以查看 updateAt
。
{
step: "Lorem",
status: "in-progress",
bool: true,
startedAt: Date.now(),
updateAt: Date.now(),
inactive: false
}
使用 CRON,这里是一些伪代码
//query
{$lte: updatedAt: today, subtracted by 2months}
//update
{$set: attr to 'whatever you want'}
//db call
db.collection.updateMany(query, update)
您好,我正在使用 mongoose/mongodb 并拥有此数据结构
{
step: "Lorem",
status: "in-progress",
bool: true,
startedAt: Date.now(),
inactive: false
}
如果前三个属性在一定时间后没有变化,如何设置inactive
为true
感谢您的帮助!
你需要一个额外的字段updateAt
,每次step
或status
或bool
改变时,你也需要改变updateAt
。
您终于可以查看 updateAt
。
{
step: "Lorem",
status: "in-progress",
bool: true,
startedAt: Date.now(),
updateAt: Date.now(),
inactive: false
}
使用 CRON,这里是一些伪代码
//query
{$lte: updatedAt: today, subtracted by 2months}
//update
{$set: attr to 'whatever you want'}
//db call
db.collection.updateMany(query, update)