From 76d67ea903cdad9cb574f197ba04e63b0747a3ca Mon Sep 17 00:00:00 2001 From: Nicholas Zolnierz Date: Wed, 19 Jan 2022 15:21:32 -0500 Subject: SERVER-62322 Allow an empty object to be projected in $setWindowFields --- jstests/aggregation/sources/setWindowFields/parse.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'jstests/aggregation') 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'); + })(); -- cgit v1.2.1