We assume that your document has created_ateither a similar field that has a time at which it was inserted or otherwise changed, depending on what is important to you.
Instead of repeating the results, you can see the option multito update to apply the changes to all documents that match your request. Setting the time you want to view should be pretty simple
In the shell syntax, which should be almost the same as the driver:
db.collection.update({
created_at: {$lt: time },
state: oldstate
},
{$set: { state: newstate } }, false, true )
The first falserelates to the upserts, which makes no sense in the use, and the second trueto multiupdate the document.
, , , total size time to live, .