Hello I am working with mongoose/mongodb and have this data structure
{
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
Thanks for any assistance!
CodePudding user response:
You need an extra field updateAt
, everytime step
or status
or bool
changed, you also need to change updateAt
.
Finally you can check updateAt
.
{
step: "Lorem",
status: "in-progress",
bool: true,
startedAt: Date.now(),
updateAt: Date.now(),
inactive: false
}
CodePudding user response:
Use a CRON, here is some pseudo code
//query
{$lte: updatedAt: today, subtracted by 2months}
//update
{$set: attr to 'whatever you want'}
//db call
db.collection.updateMany(query, update)