mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Support in minimongo
This commit is contained in:
@@ -549,12 +549,19 @@ LocalCollection.prototype.remove = function (selector, callback) {
|
||||
// we rollback the whole operation, or what?
|
||||
LocalCollection.prototype.update = function (selector, mod, options, callback) {
|
||||
var self = this;
|
||||
var newMod = _.clone(mod);
|
||||
if (! callback && options instanceof Function) {
|
||||
callback = options;
|
||||
options = null;
|
||||
}
|
||||
if (!options) options = {};
|
||||
|
||||
var setOnInsert;
|
||||
if (newMod.$setOnInsert) {
|
||||
setOnInsert = _.clone(newMod.$setOnInsert);
|
||||
delete newMod.$setOnInsert;
|
||||
}
|
||||
|
||||
var selector_f = LocalCollection._compileSelector(selector);
|
||||
|
||||
// Save the original results of any query that we might need to
|
||||
@@ -576,7 +583,7 @@ LocalCollection.prototype.update = function (selector, mod, options, callback) {
|
||||
if (selector_f(doc)) {
|
||||
// XXX Should we save the original even if mod ends up being a no-op?
|
||||
self._saveOriginal(id, doc);
|
||||
self._modifyAndNotify(doc, mod, recomputeQids);
|
||||
self._modifyAndNotify(doc, newMod, recomputeQids);
|
||||
++updateCount;
|
||||
if (!options.multi)
|
||||
break;
|
||||
@@ -591,10 +598,18 @@ LocalCollection.prototype.update = function (selector, mod, options, callback) {
|
||||
});
|
||||
self._observeQueue.drain();
|
||||
|
||||
if (setOnInsert)
|
||||
newMod.$setOnInsert = setOnInsert;
|
||||
|
||||
var insertedId;
|
||||
if (updateCount === 0 && options.upsert) {
|
||||
var newDoc = _.clone(selector);
|
||||
LocalCollection._modify(newDoc, mod);
|
||||
if (newMod.$setOnInsert) {
|
||||
newMod.$set = _.extend(newMod.$set || {},
|
||||
_.clone(newMod.$setOnInsert));
|
||||
delete newMod.$setOnInsert;
|
||||
}
|
||||
LocalCollection._modify(newDoc, newMod);
|
||||
insertedId = self.insert(newDoc);
|
||||
updateCount = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user