2024-11-08 03:34:14 -05:00
|
|
|
import { batchedUpdateWithResultHandling } from '@overleaf/mongo-utils/batchedUpdate.js'
|
|
|
|
import { db } from '../app/src/infrastructure/mongodb.js'
|
2020-10-21 05:48:30 -04:00
|
|
|
|
|
|
|
const MODEL_NAME = process.argv.pop()
|
2024-10-18 07:04:57 -04:00
|
|
|
|
|
|
|
// Todo: handle mjs file once models have been converted to ES module
|
|
|
|
const { [MODEL_NAME]: Model } = await import(
|
|
|
|
`../app/src/models/${MODEL_NAME}.js`
|
|
|
|
)
|
2020-10-21 05:48:30 -04:00
|
|
|
|
|
|
|
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 }))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 05:09:06 -04:00
|
|
|
batchedUpdateWithResultHandling(
|
2024-11-08 03:34:14 -05:00
|
|
|
db[Model.collection.name],
|
2023-03-21 05:09:06 -04:00
|
|
|
{},
|
2024-10-18 07:04:57 -04:00
|
|
|
async nextBatch => {
|
2024-11-08 03:34:14 -05:00
|
|
|
processBatch(nextBatch)
|
2023-03-21 05:09:06 -04:00
|
|
|
},
|
2024-11-08 03:34:14 -05:00
|
|
|
{} // fetch the entire record
|
2023-03-21 05:09:06 -04:00
|
|
|
)
|