Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
Mongoose runValidator with bulkWrite

I'm having issue with validators while doing a bulkoperation

verificationcount: {
  type: Number,
  default: 0,
  min: 0,
  max: 2,
},
verificationfailedcount: {
  type: Number,
  default: 0,
  min: 0,
  max: 2,
},

max and min doesn't work probably because im doing a bulk operation.

Here is my code for the bulk operation :

  const myOperations = req.body.documents.map((doc) => ({
    updateOne: {
      filter: {
        _id: doc._id,
      },
      update: {
        $inc: {
          verificationcount: doc.verificationcount,
          verificationfailedcount: doc.verificationfailedcount,
        },
        $addToSet: { opinionby: req.profile._id },
        // increase vers
      },
    },
  }));

  Document.bulkWrite(myOperations, {}, (err, docs) => {
    if (err) {
      return res.status(200).json({
        status: 'fail',
        message:
          "Operazione di aggiornamento documenti non è andata buon fine, riprova piu' tardi!",
        error: 'Operazione di bulk fallità',
      });
    }

    // TODO: SEND EMAILS TO PARTS
    return res.status(200).json({
      status: 'success',
      message: 'Documenti aggiornati con successo',
      doc: docs,
    });
  });

How can i run validators on max and min?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!