Files
overleaf-cep/services/web/scripts/validate-data-of-model.mjs
Andrew Rumble d748d8d606 Merge pull request #29795 from overleaf/ar-last-infrastructure-conversions
[web] last infrastructure conversions

GitOrigin-RevId: 68aa11625a9bc6d0d5324ecd95bb5ac52af8ee96
2025-11-27 09:05:30 +00:00

28 lines
664 B
JavaScript

import { batchedUpdateWithResultHandling } from '@overleaf/mongo-utils/batchedUpdate.js'
import { db } from '../app/src/infrastructure/mongodb.mjs'
const MODEL_NAME = process.argv.pop()
const { [MODEL_NAME]: Model } = await import(
`../app/src/models/${MODEL_NAME}.mjs`
)
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
)