diff options
author | Ted Tuckman <ted.tuckman@mongodb.com> | 2019-09-30 20:18:43 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-30 20:18:43 +0000 |
commit | 8e981e8315ab7c7bae93da623e40ffdce5b4ec6e (patch) | |
tree | 414f5e236cff2158456acb21ac12668d65c6e475 /src | |
parent | 344e1b0f3ce5caf0d4760dddc8b2d196d4b73fe8 (diff) | |
download | mongo-8e981e8315ab7c7bae93da623e40ffdce5b4ec6e.tar.gz |
SERVER-42835 Fix inconsistent handling of arrays as $group keys
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/pipeline/document_source_group.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/mongo/db/pipeline/document_source_group.cpp b/src/mongo/db/pipeline/document_source_group.cpp index 6ec80d8bbe5..2f7f32aa844 100644 --- a/src/mongo/db/pipeline/document_source_group.cpp +++ b/src/mongo/db/pipeline/document_source_group.cpp @@ -356,8 +356,11 @@ namespace { intrusive_ptr<Expression> parseIdExpression(const intrusive_ptr<ExpressionContext>& expCtx, BSONElement groupField, const VariablesParseState& vps) { - if (groupField.type() == Object && !groupField.Obj().isEmpty()) { + if (groupField.type() == Object) { // {_id: {}} is treated as grouping on a constant, not an expression + if (groupField.Obj().isEmpty()) { + return ExpressionConstant::create(expCtx, Value(groupField)); + } const BSONObj idKeyObj = groupField.Obj(); if (idKeyObj.firstElementFieldName()[0] == '$') { @@ -371,12 +374,8 @@ intrusive_ptr<Expression> parseIdExpression(const intrusive_ptr<ExpressionContex } return ExpressionObject::parse(expCtx, idKeyObj, vps); } - } else if (groupField.type() == String && groupField.valuestr()[0] == '$') { - // grouping on a field path. - return ExpressionFieldPath::parse(expCtx, groupField.str(), vps); } else { - // constant id - single group - return ExpressionConstant::create(expCtx, Value(groupField)); + return Expression::parseOperand(expCtx, groupField, vps); } } |