|
|
@ -539,13 +539,14 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { |
|
|
|
, modifications = [] |
|
|
|
, modifications = [] |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
// Preparing update (if an error is thrown here neither the datafile nor
|
|
|
|
// Preparing update (if an error is thrown here neither the datafile nor
|
|
|
|
// the in-memory indexes are affected)
|
|
|
|
// the in-memory indexes are affected)
|
|
|
|
try { |
|
|
|
try { |
|
|
|
for (i = 0; i < candidates.length; i += 1) { |
|
|
|
for (i = 0; i < candidates.length; i += 1) { |
|
|
|
if (model.match(candidates[i], query) && (multi || numReplaced === 0)) { |
|
|
|
if (model.match(candidates[i], query) && (multi || numReplaced === 0)) { |
|
|
|
numReplaced += 1; |
|
|
|
numReplaced += 1; |
|
|
|
modifiedDoc = model.modify(candidates[i], updateQuery); |
|
|
|
modifiedDoc = model.modify(candidates[i], updateQuery); |
|
|
|
|
|
|
|
if (self.timestampData) { modifiedDoc.updatedAt = new Date(); } |
|
|
|
modifications.push({ oldDoc: candidates[i], newDoc: modifiedDoc }); |
|
|
|
modifications.push({ oldDoc: candidates[i], newDoc: modifiedDoc }); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -553,14 +554,14 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { |
|
|
|
return callback(err); |
|
|
|
return callback(err); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Change the docs in memory
|
|
|
|
// Change the docs in memory
|
|
|
|
try { |
|
|
|
try { |
|
|
|
self.updateIndexes(modifications); |
|
|
|
self.updateIndexes(modifications); |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
return callback(err); |
|
|
|
return callback(err); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update the datafile
|
|
|
|
// Update the datafile
|
|
|
|
self.persistence.persistNewState(_.pluck(modifications, 'newDoc'), function (err) { |
|
|
|
self.persistence.persistNewState(_.pluck(modifications, 'newDoc'), function (err) { |
|
|
|
if (err) { return callback(err); } |
|
|
|
if (err) { return callback(err); } |
|
|
|
return callback(null, numReplaced); |
|
|
|
return callback(null, numReplaced); |
|
|
|