1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// Confirm correctness of $add evaluation in find projection.
(function() {
"use strict";
load("jstests/aggregation/extras/utils.js"); // For assertArrayEq.
load("jstests/libs/sbe_util.js"); // For checkSBEEnabled.
const isSBEEnabled = checkSBEEnabled(db);
if (isSBEEnabled) {
// Override error-code-checking APIs. We only load this when SBE is explicitly enabled, because
// it causes failures in the parallel suites.
load("jstests/libs/sbe_assert_error_override.js");
}
const coll = db.expression_add;
coll.drop();
assert.commandWorked(coll.insert({a: NumberInt(2), b: NumberLong(3), c: 3.5}));
const testCases = [
[["$a", "$b", "$c"], 8.5],
[["$a", "$b", null], null],
[["$a", "$b", 5], 10],
[[5, "$a", "$b"], 10],
[["$a", 5, "$b"], 10],
[["$a", 20, "$c", 10], 35.5],
];
for (const testCase of testCases) {
const [addExpr, expected] = testCase;
assert.eq(coll.findOne({}, {sum: {$add: addExpr}, _id: 0}), {sum: expected}, testCase);
}
})();
|