|
|
@ -249,11 +249,18 @@ lastStepModifierFunctions.$push = function (obj, field, value) { |
|
|
|
* Note that it doesn't check whether the original array contains duplicates |
|
|
|
* Note that it doesn't check whether the original array contains duplicates |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
lastStepModifierFunctions.$addToSet = function (obj, field, value) { |
|
|
|
lastStepModifierFunctions.$addToSet = function (obj, field, value) { |
|
|
|
|
|
|
|
var addToSet = true; |
|
|
|
|
|
|
|
|
|
|
|
// Create the array if it doesn't exist
|
|
|
|
// Create the array if it doesn't exist
|
|
|
|
if (!obj.hasOwnProperty(field)) { obj[field] = []; } |
|
|
|
if (!obj.hasOwnProperty(field)) { obj[field] = []; } |
|
|
|
|
|
|
|
|
|
|
|
if (!util.isArray(obj[field])) { throw "Can't $addToSet an element on non-array values"; } |
|
|
|
if (!util.isArray(obj[field])) { throw "Can't $addToSet an element on non-array values"; } |
|
|
|
if (obj[field].indexOf(value) === -1) { obj[field].push(value); } |
|
|
|
|
|
|
|
|
|
|
|
obj[field].forEach(function (v) { |
|
|
|
|
|
|
|
if (compareThings(v, value) === 0) { addToSet = false; } |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (addToSet) { obj[field].push(value); } |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|