summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorNicholas Zolnierz <nicholas.zolnierz@mongodb.com>2022-01-19 15:21:32 -0500
committerNicholas Zolnierz <nicholas.zolnierz@mongodb.com>2022-01-19 15:21:36 -0500
commit76d67ea903cdad9cb574f197ba04e63b0747a3ca (patch)
tree976097e8ca7166e0b1085e40502a8072ee67ac36 /jstests/aggregation
parentb3a66de85077da1e8304bb3e86736f1f061c5419 (diff)
downloadmongo-76d67ea903cdad9cb574f197ba04e63b0747a3ca.tar.gz
SERVER-62322 Allow an empty object to be projected in $setWindowFieldsserver-62322-setWindowFields-empty-obj
Diffstat (limited to 'jstests/aggregation')
-rw-r--r--jstests/aggregation/sources/setWindowFields/parse.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/jstests/aggregation/sources/setWindowFields/parse.js b/jstests/aggregation/sources/setWindowFields/parse.js
index 63b92e952e0..b766a76d8ae 100644
--- a/jstests/aggregation/sources/setWindowFields/parse.js
+++ b/jstests/aggregation/sources/setWindowFields/parse.js
@@ -213,8 +213,7 @@ assert.commandWorked(run({
}));
// Not every accumulator is automatically a window function.
-
-var err = assert.commandFailedWithCode(run({$setWindowFields: {output: {a: {b: {$sum: "$a"}}}}}),
+let err = assert.commandFailedWithCode(run({$setWindowFields: {output: {a: {b: {$sum: "$a"}}}}}),
ErrorCodes.FailedToParse);
assert.includes(err.errmsg, 'Expected a $-prefixed window function, b');
@@ -250,4 +249,14 @@ err = assert.commandFailedWithCode(
}),
ErrorCodes.FailedToParse);
assert.includes(err.errmsg, 'Unrecognized window function, $summ');
+
+// Test that an empty object is a valid projected field.
+assert.commandWorked(coll.insert({}));
+assert.commandWorked(run({$setWindowFields: {output: {v: {$max: {mergeObjects: {}}}}}}));
+
+// However conflicting field paths is always an error.
+err = assert.commandFailedWithCode(
+ run({$setWindowFields: {output: {a: {$sum: 1}, 'a.b': {$sum: 1}}}}), 40176);
+assert.includes(err.errmsg, 'specification contains two conflicting paths');
+
})();