summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_set_window_fields.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/document_source_set_window_fields.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_set_window_fields.cpp7
1 files changed, 5 insertions, 2 deletions
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 87cd3ad0267..09e27df140a 100644
--- a/src/mongo/db/pipeline/document_source_set_window_fields.cpp
+++ b/src/mongo/db/pipeline/document_source_set_window_fields.cpp
@@ -461,10 +461,12 @@ 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).
+ addFieldsSpec.addField(fieldName, Value(DOC("$literal" << function->getNext())));
+ } catch (const DBException&) {
// 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;
}
@@ -506,6 +508,7 @@ DocumentSource::GetNextResult DocumentSourceInternalSetWindowFields::doGetNext()
_iterator.finalize();
break;
}
+
auto projExec = projection_executor::AddFieldsProjectionExecutor::create(
pExpCtx, addFieldsSpec.freeze().toBson());