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

195
Views
How to pass candidate data to mongoose pre('validate')

When I am running this code :

        const mongoose = require('mongoose');

        const ASchema = mongoose.Schema({
            test: {
                type: String
            },
        });

        ASchema.pre('validate', function (next) {
            console.log('pre validate')
            console.log(this);

            next();
        });
        ASchema.pre('save', function (next) {
            console.log('pre save, not run')

            next();
        });

        const AModel = mongoose.model('test', ASchema);


        const a = new AModel({
            test: { value: '1' }
        });

        await a.save();

I am getting as output :

pre validate 
{ _id: new ObjectId("61c9f38e3f8f3d783d0e83c1") }

I was expecting to get :

pre validate 
{ _id: new ObjectId("61c9f38e3f8f3d783d0e83c1"), test: { value: '1' } }

I want to get the test field in pre('validate') function even if it's not valid so I can process it. Is that possible ?

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!