summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorauto-revert-processor <dev-prod-dag@mongodb.com>2022-01-21 06:48:21 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-21 07:16:02 +0000
commit2ea6389bf7069644616b3ab7b9f67002c8554870 (patch)
treed58ebe36e43320d0e2df43163de7398afa7175e2
parent1f15a513cddc07b77328dea84861775878ece876 (diff)
downloadmongo-2ea6389bf7069644616b3ab7b9f67002c8554870.tar.gz
Revert "SERVER-62322 Allow an empty object to be projected in $setWindowFields"
This reverts commit 2dac3294841b0374a94a5823f3726d5d02e27261.
-rw-r--r--jstests/aggregation/sources/setWindowFields/parse.js12
-rw-r--r--src/mongo/db/pipeline/document_source_set_window_fields.cpp9
2 files changed, 5 insertions, 16 deletions
diff --git a/jstests/aggregation/sources/setWindowFields/parse.js b/jstests/aggregation/sources/setWindowFields/parse.js
index c61839f27b8..63b92e952e0 100644
--- a/jstests/aggregation/sources/setWindowFields/parse.js
+++ b/jstests/aggregation/sources/setWindowFields/parse.js
@@ -213,7 +213,8 @@ assert.commandWorked(run({
}));
// Not every accumulator is automatically a window function.
-let err = assert.commandFailedWithCode(run({$setWindowFields: {output: {a: {b: {$sum: "$a"}}}}}),
+
+var err = assert.commandFailedWithCode(run({$setWindowFields: {output: {a: {b: {$sum: "$a"}}}}}),
ErrorCodes.FailedToParse);
assert.includes(err.errmsg, 'Expected a $-prefixed window function, b');
@@ -249,13 +250,4 @@ 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');
})();
diff --git a/src/mongo/db/pipeline/document_source_set_window_fields.cpp b/src/mongo/db/pipeline/document_source_set_window_fields.cpp
index d736f56845d..87cd3ad0267 100644
--- a/src/mongo/db/pipeline/document_source_set_window_fields.cpp
+++ b/src/mongo/db/pipeline/document_source_set_window_fields.cpp
@@ -461,11 +461,9 @@ DocumentSource::GetNextResult DocumentSourceInternalSetWindowFields::doGetNext()
MutableDocument addFieldsSpec;
for (auto&& [fieldName, function] : _executableOutputs) {
try {
- // Wrap the projected value in a $literal since there are limitations on a user-facing
- // $addFields that we don't want to enforce here (e.g. empty object). If we hit a
- // uassert while evaluating expressions on user data, delete the temporary table before
- // aborting the operation.
- addFieldsSpec.addField(fieldName, Value(DOC("$literal" << function->getNext())));
+ // If we hit a uassert while evaluating expressions on user data, delete the temporary
+ // table before aborting the operation.
+ addFieldsSpec.addField(fieldName, function->getNext());
} catch (const DBException&) {
_iterator.finalize();
throw;
@@ -508,7 +506,6 @@ DocumentSource::GetNextResult DocumentSourceInternalSetWindowFields::doGetNext()
_iterator.finalize();
break;
}
-
auto projExec = projection_executor::AddFieldsProjectionExecutor::create(
pExpCtx, addFieldsSpec.freeze().toBson());