mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-03 08:21:48 -05:00
252533b2fd
[mongo-utils] create new home for batchedUpdate helper GitOrigin-RevId: 9f61c5e367a9f4cef63b5cc4c0bbbd3ef57c8ca8
28 lines
732 B
JavaScript
28 lines
732 B
JavaScript
import { batchedUpdateWithResultHandling } from '@overleaf/mongo-utils/batchedUpdate.js'
|
|
import { db } from '../app/src/infrastructure/mongodb.js'
|
|
|
|
const MODEL_NAME = process.argv.pop()
|
|
|
|
// Todo: handle mjs file once models have been converted to ES module
|
|
const { [MODEL_NAME]: Model } = await import(
|
|
`../app/src/models/${MODEL_NAME}.js`
|
|
)
|
|
|
|
function processBatch(batch) {
|
|
for (const doc of batch) {
|
|
const error = new Model(doc).validateSync()
|
|
if (error) {
|
|
const { errors } = error
|
|
console.log(JSON.stringify({ _id: doc._id, errors }))
|
|
}
|
|
}
|
|
}
|
|
|
|
batchedUpdateWithResultHandling(
|
|
db[Model.collection.name],
|
|
{},
|
|
async nextBatch => {
|
|
processBatch(nextBatch)
|
|
},
|
|
{} // fetch the entire record
|
|
)
|