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

421
Vistas
Getting Version error in mongoDB while using save() method

I am getting this version error in MongoDB due to the save() method. I did some research about it and got to know that the save method uses versioning. To skip it we can use the update method, but by using update, I am getting another error "Performing an update on the path '_id' would modify the immutable field '_id".

Is there any other way to solve this version error?

code example:

let fileDoc = await File.findById(req.params.id);

    fileDoc.history.unshift({
      user: req.user._id,
      status: status,
      createdAt: new Date()
    });

    if (is_false_reject) {
      fileDoc.isFalseReject = is_false_reject;
      fileDoc.falseRejectedAt = new Date();
    }

    fileDoc.status = status;
    fileDoc.comment = comment;
    await fileDoc.save();

Error by save() method: VersionError: No matching document found for id "e6a83b9b-42be-41b7-87ed-e21eff052c61.pdf" version 2 modifiedPaths "history, status" at generateVersionError (/home/node/app/node_modules/mongoose/lib/model.js:439:10) at model.Model.save (/home/node/app/node_modules/mongoose/lib/model.js:495:28) at /home/node/app/helpers/file.js:525:23 at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:94:5) { version: 2, modifiedPaths: [ 'history', 'status' ]

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Please look on https://mongoosejs.com/docs/guide.html#versionKey

We can disable the version key in mongoose but that is not a best practice, Please review the documentation.

If you face issue after this solution please comment, I will try my best to solve your issue

about 4 years ago · Juan Pablo Isaza Denunciar
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