diff --git a/lib/error/version.js b/lib/error/version.js index 33d1bd88e66..eed37fd5888 100644 --- a/lib/error/version.js +++ b/lib/error/version.js @@ -13,11 +13,13 @@ var MongooseError = require('./'); * @api private */ -function VersionError(doc, currentVersion) { +function VersionError(doc, currentVersion, modifiedPaths) { + var modifiedPathsStr = modifiedPaths.join(', '); MongooseError.call(this, 'No matching document found for id "' + doc._id + - '" version ' + currentVersion); + '" version ' + currentVersion + ' modifiedPaths "' + modifiedPathsStr + '"'); this.name = 'VersionError'; this.version = currentVersion; + this.modifiedPaths = modifiedPaths; } /*! diff --git a/lib/model.js b/lib/model.js index e502bc8479f..f0ba6eb4324 100644 --- a/lib/model.js +++ b/lib/model.js @@ -229,6 +229,9 @@ Model.prototype.$__save = function(options, callback) { }); } + // store the modified paths before the document is reset + var modifiedPaths = _this.modifiedPaths(); + _this.$__reset(); var numAffected = 0; @@ -263,7 +266,7 @@ Model.prototype.$__save = function(options, callback) { if (numAffected <= 0) { // the update failed. pass an error back - var err = new VersionError(_this, version); + var err = new VersionError(_this, version, modifiedPaths); return callback(err); } diff --git a/test/versioning.test.js b/test/versioning.test.js index 4e6856c8b08..4fa34acd7c9 100644 --- a/test/versioning.test.js +++ b/test/versioning.test.js @@ -266,6 +266,7 @@ describe('versioning', function() { assert.ok(/No matching document/.test(err), err); assert.equal(a._doc.__v, 5); assert.equal(err.version, b._doc.__v - 1); + assert.deepEqual(err.modifiedPaths, ['numbers', 'numbers.2']); a.set('arr.0.0', 'updated'); var d = a.$__delta(); assert.equal(a._doc.__v, d[0].__v, 'version should be added to where clause');