Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda