javascript - MongoDB query for document older than 30 seconds -


does have approach query against collection documents older 30 seconds. i'm creating cleanup worker marks items failed after have been in specific state more 30 seconds.

not matters, i'm using mongojs one.

every document has created time associated it.

we assuming have created_at or similar field in document has time inserted or otherwise modified depending on important you.

rather iterate on results might want @ multi option in update apply change documents match query. setting time want past should straightforward

in shell syntax, should pretty same of driver:

db.collection.update({      created_at: {$lt: time },      state: oldstate  }, {$set: { state: newstate } }, false, true ) 

the first false being upserts not make sense in usage , second true marking multi document update.

if documents indeed going short lived , have no other need them afterwards, might consider capped collections. can have total size or time live option these , natural insertion order favours processing of queued entries.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -