Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support _id aggregation operators for $group stage #3096

Merged
merged 19 commits into from
Jul 26, 2023
Prev Previous commit
Next Next commit
wip
  • Loading branch information
noisersup committed Jul 25, 2023
commit e02bb2ae99f1b8c6bcf79289f6c52739b66ec9fa
36 changes: 36 additions & 0 deletions integration/aggregate_documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,42 @@ func TestAggregateGroupErrors(t *testing.T) {
Message: "Unrecognized expression '$non-existent'",
},
},
"SumEmptyExpression": {
pipeline: bson.A{
bson.D{{"$group", bson.D{
{"sum", bson.D{{"$sum", "$"}}},
}}},
},
err: &mongo.CommandError{
Code: 16872,
Name: "Location16872",
Message: "'$' by itself is not a valid FieldPath",
},
},
"SumEmptyVariable": {
pipeline: bson.A{
bson.D{{"$group", bson.D{
{"_id", bson.D{{"$sum", "$$"}}},
}}},
},
err: &mongo.CommandError{
Code: 9,
Name: "FailedToParse",
Message: "Invalid $group :: caused by :: empty variable names are not allowed",
},
},
"SumDollarVariable": {
pipeline: bson.A{
bson.D{{"$group", bson.D{
{"_id", bson.D{{"$sum", "$$$"}}},
}}},
},
err: &mongo.CommandError{
Code: 9,
Name: "FailedToParse",
Message: "Invalid $group :: caused by :: '$' starts with an invalid character for a user variable name",
},
},
"GroupRecursiveNonExistentOperator": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$type", bson.D{{"$non-existent", "foo"}}}}}}}},
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/common/aggregations/stages/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (m *groupMap) addOrAppend(groupKey any, docs ...*types.Document) {
}

// processOperatorError takes internal error related to operator evaluation and
// returns proper CommandError that can be returned by $project aggregation stage.
// returns proper CommandError that can be returned by $group aggregation stage.
//
// Command error codes:
// - ErrEmptySubProject when operator value is empty.
chilagrow marked this conversation as resolved.
Show resolved Hide resolved
Expand Down