When I try to save my document, I get a VersionError: No matching document found error similar to this SO question.
After reading this blog post, it looks like the problem is with the version of my document. That I was messing around with the array, so I need to update the version.
However, calling document.save() does not work for me. When I exit a document before and after calling save() , document._v is one and the same.
I also tried making document._v = document._v++ , which also didn't work.
code
exports.update = function(req, res) { if (req.body._id) { delete req.body._id; } User.findById(req.params.id, function(err, user) { if (err) return handleError(res, err); if (!user) return res.send(404); var updated = _.extend(user, req.body);
Output
pre increment: { _id: 5550baae1b571aafa52f070c, provider: 'local', name: 'Adam', email: ' azerner3@gmail.com ', hashedPassword: '/vahOqXwCwKQKtcV3KBQeFge/YB0xtqOj+YDyck7gzyALA/IP7u7BfqQhlVHBQT26//XfBTkaOCK2bQXg65OzA==', salt: 'MvzXW7D4xuyGQBJNeFRoUg==', __v: 32, drafts: [], starredSkims: [], skimsCreated: [ 5550cfdab8dcacd1a7892aa4 ], role: 'user' } post increment: { _id: 5550baae1b571aafa52f070c, provider: 'local', name: 'Adam', email: ' azerner3@gmail.com ', hashedPassword: '/vahOqXwCwKQKtcV3KBQeFge/YB0xtqOj+YDyck7gzyALA/IP7u7BfqQhlVHBQT26//XfBTkaOCK2bQXg65OzA==', salt: 'MvzXW7D4xuyGQBJNeFRoUg==', __v: 32, drafts: [], starredSkims: [], skimsCreated: [ 5550cfdab8dcacd1a7892aa4 ], role: 'user' }