diff --git a/packages/minimongo/minimongo.js b/packages/minimongo/minimongo.js index c1f2a21771..59cd1be837 100644 --- a/packages/minimongo/minimongo.js +++ b/packages/minimongo/minimongo.js @@ -549,19 +549,12 @@ 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 @@ -583,7 +576,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, newMod, recomputeQids); + self._modifyAndNotify(doc, mod, recomputeQids); ++updateCount; if (!options.multi) break; @@ -598,18 +591,10 @@ 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); - if (newMod.$setOnInsert) { - newMod.$set = _.extend(newMod.$set || {}, - _.clone(newMod.$setOnInsert)); - delete newMod.$setOnInsert; - } - LocalCollection._modify(newDoc, newMod); + LocalCollection._modify(newDoc, mod, true); insertedId = self.insert(newDoc); updateCount = 1; } diff --git a/packages/minimongo/modify.js b/packages/minimongo/modify.js index 8413899eb1..0e404914dd 100644 --- a/packages/minimongo/modify.js +++ b/packages/minimongo/modify.js @@ -147,6 +147,9 @@ LocalCollection._modifiers = { target[field] = EJSON.clone(arg); }, + $setOnInsert: function (target, field, arg) { + // converted to `$set` in `_modify` + }, $unset: function (target, field, arg) { if (target !== undefined) { if (target instanceof Array) {