I want to fetch all updated documents from MongoDB using pymongo.
I tried using findOneAndUpdate() but it only updates one document. Also tried using MongoDB js server function, but it is too slow and mostly not recommended.
db.system.js.save({
_id: "distributedTaskQueue",
value : function(coll,status,limit,fromStatus,toStatus) {
records = db.getCollection(coll).find({status:fromStatus}).limit(limit)
results.forEach (function(record){
record[status]= toStatus
db.getCollection(coll).save(record);
})
return records;
}
})
The idea is to run this on 100 servers using pymongo to fetch documents for processing.