Dont throw an error if updateQuery contains an _id that is the same as obj

pull/2/head
Louis Chatriot 12 years ago
parent 0eaa3f7a04
commit fd6bc22e56
  1. 2
      lib/model.js
  2. 2
      package.json
  3. 5
      test/model.test.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";

@ -1,6 +1,6 @@
{
"name": "nedb",
"version": "0.3.0",
"version": "0.3.1",
"author": {
"name": "tldr.io",
"email": "hello@tldr.io"

@ -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 () {

Loading…
Cancel
Save