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

166
Views
NodeJs Mongoose passing parameters to post findOneAndUpdate

I want to use post findOneAndUpdate middlewares to save a log datas of all my mongoose model changes.

I use findOneAndUpdate in three places:

 - Update Model's data
 - change Model status
 - archive / restore Model

So when I use the post findOneAndUpdate middlewares, I want to Knwo wich one of the three findOneAndUpdate was executed.

Is there a way to pass parameters from findOneAndUpdate to post findOneAndUpdate middlewares.?

There is my Code:

controller: invoices.js

    update: function (request, response, next) {
    //checking general invoice information
    request.checkBody(typeValidationSchema);
    request.getValidationResult().then(function(result) {
        if (!result.isEmpty()) return response.apiError(result.array());
        else {
            Invoice.findOneAndUpdate({
                _id: request.params.invoiceId,
                createdBy: request.user._id
            }, request.body, {'new': true, 'runValidators': true}).exec(function (error, invoice) {
                if (error) response.apiError(error);
                if (!invoice) return response.apiNotFound();
                else return response.apiResponse(invoice);
            });
        }
    });
},

Model Schema: invoice.js

InvoiceSchema.post('findOneAndUpdate', function(doc) {
// I want to get her some variables passed from controller findOneAndUpdate
});
about 4 years ago · Santiago Trujillo
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!