diff --git a/lib/model.js b/lib/model.js index dc09ca711dd..3970f592840 100644 --- a/lib/model.js +++ b/lib/model.js @@ -652,8 +652,13 @@ Model.prototype.$__version = function(where, delta) { } if (VERSION_INC === (VERSION_INC & this.$__.version)) { - if (!delta.$set || typeof delta.$set[key] === 'undefined') { - delta.$inc || (delta.$inc = {}); + if (get(delta.$set, key, null) != null) { + // Version key is getting set, means we'll increment the doc's version + // after a successful save, so we should set the incremented version so + // future saves don't fail (gh-5779) + ++delta.$set[key]; + } else { + delta.$inc = delta.$inc || {}; delta.$inc[key] = 1; } }