mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
$setOnInsert in minimongo
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user