[英]How do I make a function tick atomically if the document is not modified after a certain period of time
Hello I am working with mongoose/mongodb and have this data structure您好,我正在使用 mongoose/mongodb 并具有此数据结构
{
step: "Lorem",
status: "in-progress",
bool: true,
startedAt: Date.now(),
inactive: false
}
how do I make it so if there are no changes to the first three attibutes after a certain period of time inactive
is set to true如果在一定时间后
inactive
设置为真后前三个属性没有更改,我该怎么做
Thanks for any assistance!感谢您的帮助!
You need an extra field updateAt
, everytime step
or status
or bool
changed, you also need to change updateAt
.您需要一个额外的字段
updateAt
,每次step
或status
或bool
更改时,您还需要更改updateAt
。
Finally you can check updateAt
.最后你可以检查
updateAt
。
{
step: "Lorem",
status: "in-progress",
bool: true,
startedAt: Date.now(),
updateAt: Date.now(),
inactive: false
}
Use a CRON, here is some pseudo code使用 CRON,这里是一些伪代码
//query
{$lte: updatedAt: today, subtracted by 2months}
//update
{$set: attr to 'whatever you want'}
//db call
db.collection.updateMany(query, update)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.