|
|
|
@ -240,9 +240,8 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { |
|
|
|
|
, self = this |
|
|
|
|
, numReplaced = 0 |
|
|
|
|
, multi, upsert |
|
|
|
|
, modifiedDoc |
|
|
|
|
, newData = [] |
|
|
|
|
, updatedDocs = [] |
|
|
|
|
, i |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
if (typeof options === 'function') { cb = options; options = {}; } |
|
|
|
@ -270,24 +269,19 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { |
|
|
|
|
} |
|
|
|
|
, function () { // Perform the update
|
|
|
|
|
try { |
|
|
|
|
self.data.forEach(function (d) { |
|
|
|
|
if (model.match(d, query) && (multi || numReplaced === 0)) { |
|
|
|
|
for (i = 0; i < self.data.length; i += 1) { |
|
|
|
|
if (model.match(self.data[i], query) && (multi || numReplaced === 0)) { |
|
|
|
|
numReplaced += 1; |
|
|
|
|
modifiedDoc = model.modify(d, updateQuery); |
|
|
|
|
|
|
|
|
|
newData.push(modifiedDoc); |
|
|
|
|
updatedDocs.push(modifiedDoc); |
|
|
|
|
} else { |
|
|
|
|
newData.push(d); |
|
|
|
|
self.data[i] = model.modify(self.data[i], updateQuery); |
|
|
|
|
updatedDocs.push(self.data[i]); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} catch (err) { |
|
|
|
|
return callback(err); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.persistNewState(updatedDocs, function (err) { |
|
|
|
|
if (err) { return callback(err); } |
|
|
|
|
self.data = newData; |
|
|
|
|
return callback(null, numReplaced); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|