|
|
@@ -8,6 +8,7 @@
|
|
|
* @module mungedb-aggregate
|
|
|
* @constructor
|
|
|
**/
|
|
|
+
|
|
|
var SetUnionExpression = module.exports = function SetUnionExpression() {
|
|
|
this.nargs = 2;
|
|
|
base.call(this);
|
|
|
@@ -29,24 +30,28 @@ proto.getOpName = function getOpName() {
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Takes 2 objects. Unions the objects
|
|
|
+ * Takes 2 objects. Returns the union of the two objects.
|
|
|
* @method evaluateInternal
|
|
|
**/
|
|
|
proto.evaluateInternal = function evaluateInternal(vars) {
|
|
|
+
|
|
|
+ var unionSet = {};
|
|
|
+
|
|
|
var object1 = this.operands[0].evaluateInternal(vars),
|
|
|
object2 = this.operands[1].evaluateInternal(vars);
|
|
|
- if (object1 instanceof Array) throw new Error(this.getOpName() + ": object 1 must be an object");
|
|
|
- if (object2 instanceof Array) throw new Error(this.getOpName() + ": object 2 must be an object");
|
|
|
|
|
|
- var object3 = {};
|
|
|
+ //Deviation from Mongo. We are using objects for this, while they use arrays.
|
|
|
+ if (typeof object1 != object) throw new Error("All operands of " + this.getOpName() + "must be objects. First argument is of type: " + typeof object1);
|
|
|
+ if (typeof object2 != object) throw new Error("All operands of " + this.getOpName() + "must be objects. Second argument is of type: " + typeof object2);
|
|
|
+
|
|
|
for (var attrname1 in object1) {
|
|
|
- object3[attrname1] = object1[attrname1];
|
|
|
+ unionSet[attrname1] = object1[attrname1];
|
|
|
}
|
|
|
for (var attrname2 in object2) {
|
|
|
- object3[attrname2] = object2[attrname2];
|
|
|
+ unionSet[attrname2] = object2[attrname2];
|
|
|
}
|
|
|
|
|
|
- return object3;
|
|
|
+ return unionSet;
|
|
|
};
|
|
|
|
|
|
/** Register Expression */
|