Working with mongoose and Express for a basic data endpoint, and I'm having trouble with the Update
portion of the CRUD operations.
Testing the Update path works in Postman, but when I try from my angular app, it returns this:
MongoError: Updating the path '__v' would create a conflict at '__v' at C:\Users\rutherfordc.AA\Documents\GitHub\techInventory\node_modules\mongoose\node_modules\mongodb-core\lib\conne ction\pool.js:595:61 at authenticateStragglers (C:\Users\rutherfordc.AA\Documents\GitHub\techInventory\node_modules\mongoose\node_module s\mongodb-core\lib\connection\pool.js:513:16) at Connection.messageHandler (C:\Users\rutherfordc.AA\Documents\GitHub\techInventory\node_modules\mongoose\node_mod ules\mongodb-core\lib\connection\pool.js:549:5) at emitMessageHandler (C:\Users\rutherfordc.AA\Documents\GitHub\techInventory\node_modules\mongoose\node_modules\mo ngodb-core\lib\connection\connection.js:309:10) at Socket. (C:\Users\rutherfordc.AA\Documents\GitHub\techInventory\node_modules\mongoose\node_modules\mo ngodb-core\lib\connection\connection.js:452:17) at Socket.emit (events.js:160:13) at addChunk (_stream_readable.js:269:12) at readableAddChunk (_stream_readable.js:256:11) at Socket.Readable.push (_stream_readable.js:213:10) at TCP.onread (net.js:602:20)
I don't really want to update __v
but I don't understand why it's being triggered. How can I force it to be ignored?
here's my update method:
update(req,res){
let _computer = req.body;
let _id = req.params.computerId;
Computer.findOneAndUpdate({'_id':_id}, _computer, {upsert: true}, (err, uc) => {
if(err){
log.error(err);
res.status(500).send(err);
}else{
res.status(200).send(uc);
}
});
}
__v
being sent in the request body? - foxinatardisdelete _computer.__v
before callingfindOneAndUpdate
? You could also try setting up hooks on your find queries to exclude __v from the returned results so __v never gets to your front end if that applies to your situation. - foxinatardisread()
andreadOne()
handlers just dodelete obj.__v;
beforeres.send()
? - Chris Rutherford