|
|
@ -476,12 +476,12 @@ Datastore.prototype.findOne = function (query, projection, callback) { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Update all docs matching query |
|
|
|
* Update all docs matching query |
|
|
|
* For now, very naive implementation (recalculating the whole database) |
|
|
|
|
|
|
|
* @param {Object} query |
|
|
|
* @param {Object} query |
|
|
|
* @param {Object} updateQuery |
|
|
|
* @param {Object} updateQuery |
|
|
|
* @param {Object} options Optional options |
|
|
|
* @param {Object} options Optional options |
|
|
|
* options.multi If true, can update multiple documents (defaults to false) |
|
|
|
* options.multi If true, can update multiple documents (defaults to false) |
|
|
|
* options.upsert If true, document is inserted if the query doesn't match anything |
|
|
|
* options.upsert If true, document is inserted if the query doesn't match anything |
|
|
|
|
|
|
|
* options.returnUpdatedDocs Defaults to false, if true return as third argument the array of updated matched documents (even if no change actually took place) |
|
|
|
* @param {Function} cb Optional callback, signature: err, numReplaced, upsert (set to true if the update was in fact an upsert) |
|
|
|
* @param {Function} cb Optional callback, signature: err, numReplaced, upsert (set to true if the update was in fact an upsert) |
|
|
|
* |
|
|
|
* |
|
|
|
* @api private Use Datastore.update which has the same signature |
|
|
|
* @api private Use Datastore.update which has the same signature |
|
|
@ -562,9 +562,16 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update the datafile
|
|
|
|
// Update the datafile
|
|
|
|
self.persistence.persistNewState(_.pluck(modifications, 'newDoc'), function (err) { |
|
|
|
var updatedDocs = _.pluck(modifications, 'newDoc'); |
|
|
|
|
|
|
|
self.persistence.persistNewState(updatedDocs, function (err) { |
|
|
|
if (err) { return callback(err); } |
|
|
|
if (err) { return callback(err); } |
|
|
|
return callback(null, numReplaced); |
|
|
|
if (!options.returnUpdatedDocs) { |
|
|
|
|
|
|
|
return callback(null, numReplaced); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var updatedDocsDC = []; |
|
|
|
|
|
|
|
updatedDocs.forEach(function (doc) { updatedDocsDC.push(model.deepCopy(doc)); }); |
|
|
|
|
|
|
|
return callback(null, numReplaced, updatedDocsDC); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
]); |
|
|
|
]); |
|
|
|