diff --git a/lib/datastore.js b/lib/datastore.js index dbff47b..871e06f 100644 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -242,7 +242,7 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { , multi, upsert , modifiedDoc , newData = [] - , updatedData = [] + , updatedDocs = [] ; if (typeof options === 'function') { cb = options; options = {}; } @@ -276,7 +276,7 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { modifiedDoc = model.modify(d, updateQuery); newData.push(modifiedDoc); - updatedData.push(modifiedDoc); + updatedDocs.push(modifiedDoc); } else { newData.push(d); } @@ -285,7 +285,7 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { return callback(err); } - self.persistNewState(updatedData, function (err) { + self.persistNewState(updatedDocs, function (err) { if (err) { return callback(err); } self.data = newData; return callback(null, numReplaced); @@ -313,7 +313,9 @@ Datastore.prototype._remove = function (query, options, cb) { , self = this , numRemoved = 0 , multi - , newData = []; + , newData = [] + , removedDocs = [] + ; if (typeof options === 'function') { cb = options; options = {}; } callback = cb || function () {}; @@ -323,6 +325,7 @@ Datastore.prototype._remove = function (query, options, cb) { self.data.forEach(function (d) { if (model.match(d, query) && (multi || numRemoved === 0)) { numRemoved += 1; + removedDocs.push({ $$deleted: true, _id: d._id }); } else { newData.push(d); } @@ -331,7 +334,7 @@ Datastore.prototype._remove = function (query, options, cb) { return callback(err); } - self.persistWholeDatabase(newData, function (err) { + self.persistNewState(removedDocs, function (err) { if (err) { return callback(err); } self.data = newData; return callback(null, numRemoved);