Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

417
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda