Been working with node
and mongoose
lately and I enjoyed it until I had to update a model.
Here is what I'm doing:
module.exports.update = (post, cb) ->
Post.update _id: post._id, post, (err, data) ->
cb(err, data)
So I thought it'll be a easy as saving a new post but it's complaining with error:
err: 'Mod on _id not allowed'
I tried to delete post._id
before passing it to my update method, but it didn't work and I
couldn't find any good examples on how to do it except one that looks
a bit odd where first you find Post
by _id
, then update each key
manually and save Post back again...
Any suggestions?
You were on the right track with deleting
post._id
before passing it toupdate
. Assumingpost
is a plain JS object, this should work: