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

411
Views
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 answers
Answer question

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 Report
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!