diff --git a/lib/model.js b/lib/model.js index 0aebe56..af7c306 100644 --- a/lib/model.js +++ b/lib/model.js @@ -184,7 +184,7 @@ function modify (obj, updateQuery) { , newDoc, modifiers ; - if (keys.indexOf('_id') !== -1) { throw "You cannot change a document's _id"; } + if (keys.indexOf('_id') !== -1 && updateQuery._id !== obj._id) { throw "You cannot change a document's _id"; } if (dollarFirstChars.length !== 0 && dollarFirstChars.length !== firstChars.length) { throw "You cannot mix modifiers and normal fields"; diff --git a/package.json b/package.json index d440778..5a06803 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nedb", - "version": "0.3.0", + "version": "0.3.1", "author": { "name": "tldr.io", "email": "hello@tldr.io" diff --git a/test/model.test.js b/test/model.test.js index df9c08b..758787d 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -212,7 +212,7 @@ describe('Model', function () { t._id.should.equal('keepit'); }); - it('Throw an error if trying to replace the _id field in a copy-type modification', function () { + it('Throw an error if trying to change the _id field in a copy-type modification', function () { var obj = { some: 'thing', _id: 'keepit' } , updateQuery = { replace: 'done', bloup: [ 1, 8], _id: 'donttryit' } ; @@ -220,6 +220,9 @@ describe('Model', function () { (function () { model.modify(obj, updateQuery); }).should.throw(); + + updateQuery._id = 'keepit'; + model.modify(obj, updateQuery); // No error thrown }); it('Throw an error if trying to use modify in a mixed copy+modify way', function () {