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
tests
  • Loading branch information
noisersup committed Jul 24, 2023
commit acd30463be3fa41d93bfceb45b55c8f3d005308c
52 changes: 51 additions & 1 deletion integration/aggregate_documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestAggregateGroupErrors(t *testing.T) {
altMessage string // optional, alternative error message for FerretDB, ignored if empty
skip string // optional, skip test with a specified reason
}{
"StageGroupUnaryOperatorSum": {
"GroupUnaryOperatorSum": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"sum", bson.D{{"$sum", bson.A{}}}}}}},
},
Expand All @@ -105,6 +105,56 @@ func TestAggregateGroupErrors(t *testing.T) {
},
altMessage: "The $sum accumulator is a unary operator",
},
"GroupTypeEmpty": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"v", bson.D{}}}}},
},
err: &mongo.CommandError{
Code: 40234,
Name: "Location40234",
Message: "The field 'v' must be an accumulator object",
},
},
"GroupTwoOperators": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$type", int32(42)}, {"$op", int32(42)}}}}}},
},
err: &mongo.CommandError{
Code: 15983,
Name: "Location15983",
Message: "An object representing an expression must have exactly one field: { $type: 42, $op: 42 }",
},
},
"GroupTypeInvalidLen": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$type", bson.A{"foo", "bar"}}}}}}},
},
err: &mongo.CommandError{
Code: 16020,
Name: "Location16020",
Message: "Expression $type takes exactly 1 arguments. 2 were passed in.",
},
},
"GroupNonExistentOperator": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$non-existent", "foo"}}}}}},
},
err: &mongo.CommandError{
Code: 168,
Name: "InvalidPipelineOperator",
Message: "Unrecognized expression '$non-existent'",
},
},
"GroupRecursiveNonExistentOperator": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$type", bson.D{{"$non-existent", "foo"}}}}}}}},
},
err: &mongo.CommandError{
Code: 168,
Name: "InvalidPipelineOperator",
Message: "Unrecognized expression '$non-existent'",
},
},
chilagrow marked this conversation as resolved.
Show resolved Hide resolved
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
Expand Down