|
@@ -8,6 +8,7 @@ if (process.env.BATCH_LAST_ID) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function getNextBatch(collection, query, maxId, projection) {
|
|
async function getNextBatch(collection, query, maxId, projection) {
|
|
|
|
|
+ maxId = maxId || BATCH_LAST_ID
|
|
|
if (maxId) {
|
|
if (maxId) {
|
|
|
query['_id'] = { $gt: maxId }
|
|
query['_id'] = { $gt: maxId }
|
|
|
}
|
|
}
|
|
@@ -35,7 +36,7 @@ async function batchedUpdate(collectionName, query, update, projection) {
|
|
|
projection = projection || { _id: 1 }
|
|
projection = projection || { _id: 1 }
|
|
|
let nextBatch
|
|
let nextBatch
|
|
|
let updated = 0
|
|
let updated = 0
|
|
|
- let maxId = BATCH_LAST_ID
|
|
|
|
|
|
|
+ let maxId
|
|
|
while (
|
|
while (
|
|
|
(nextBatch = await getNextBatch(collection, query, maxId, projection))
|
|
(nextBatch = await getNextBatch(collection, query, maxId, projection))
|
|
|
.length
|
|
.length
|
|
@@ -66,6 +67,7 @@ function batchedUpdateWithResultHandling(collection, query, update) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
|
|
+ getNextBatch,
|
|
|
batchedUpdate,
|
|
batchedUpdate,
|
|
|
batchedUpdateWithResultHandling
|
|
batchedUpdateWithResultHandling
|
|
|
}
|
|
}
|