validate-data-of-model.js 555 B

1234567891011121314151617181920212223
  1. const { batchedUpdateWithResultHandling } = require('./helpers/batchedUpdate')
  2. const MODEL_NAME = process.argv.pop()
  3. const Model = require(`../app/src/models/${MODEL_NAME}`)[MODEL_NAME]
  4. function processBatch(batch) {
  5. for (const doc of batch) {
  6. const error = new Model(doc).validateSync()
  7. if (error) {
  8. const { errors } = error
  9. console.log(JSON.stringify({ _id: doc._id, errors }))
  10. }
  11. }
  12. }
  13. batchedUpdateWithResultHandling(
  14. Model.collection.name,
  15. {},
  16. async (_, nextBatch) => {
  17. await processBatch(nextBatch)
  18. },
  19. {}
  20. )