I have x local registers which synchronise with a central one. I want to either modify the old doc or insert a new one into the central register. I rename the original id in the central register to avoid id conflicts.
I also need the new doc as a return value, so that I can store the _id
of the central register in my local register.
Thats why I use:
PatientModel.findOneAndUpdate({
refId: new ObjectId(patient.refId),
institute: new ObjectId(patient.institute),
deleted: false
}, patient, { 'upsert':true, 'new': true }, (err, patientFound) ->
But I get this error:
{ [MongoError: exception: Cannot update '__v' and '__v' at the same time]
name: 'MongoError',
message: 'exception: Cannot update \'__v\' and \'__v\' at the same time',
errmsg: 'exception: Cannot update \'__v\' and \'__v\' at the same time',
code: 16836,
ok: 0 }
If I transform the bson objects into javascript objects first and then delete the __v
property, the error does not appear. I only have docs with __v == 0
. I don't think it is a good solution because I may need the __v
property later.
Questions
1) What is causing this error 2) How to handle this
I found this but I don't understand why this should help: Mongoose error: Cannot update __v and __v at the same time