Created
December 9, 2011 16:42
-
-
Save elephant/1452287 to your computer and use it in GitHub Desktop.
Delay the execution of MongoDB update queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//function to be executed on a "delayed" fashion, use on a mongodb query.forEach() | |
var delayedUpdateFn = function(theDocument) { | |
var waitMilliseconds = 500; //change to whatever delay you want | |
var waitUntil = Date.now() + waitMilliseconds; | |
while(Date.now() < waitUntil) { | |
//sleep | |
} | |
//insert code to execute on this document | |
//theDocument.something = "hello"; | |
}; | |
//example usage on a query: | |
db.listings.find({"_types":{$in:["VacationRentalListing"]}}).forEach(delayedUpdateFn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
//function to be executed on a "delayed" fashion, use on a mongodb query.forEach()
async function delayedUpdateFn(theDocument) {
var waitMilliseconds = 500; //change to whatever delay you want
var waitUntil = Date.now() + waitMilliseconds;
while(Date.now() < waitUntil) {
await sleep(5000);
}
//insert code to execute on this document
//theDocument.something = "hello";
};
//example usage on a query:
db.listings.find({"_types":{$in:["VacationRentalListing"]}}).forEach(delayedUpdateFn);`
Реализация паузы в цикле)))