Skip to content

Commit 8d46367

Browse files
feat(aggregation):
- fix
1 parent 21b14be commit 8d46367

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

builder/aggregation/bson_construction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func Sum(key string, expression any) bson.D {
2525
return bson.D{bson.E{Key: key, Value: bson.D{bson.E{Key: types.AggregationSum, Value: expression}}}}
2626
}
2727

28-
func Push(expression any) bson.D {
29-
return bson.D{bson.E{Key: types.AggregationPush, Value: expression}}
28+
func Push(key string, expression any) bson.D {
29+
return bson.D{bson.E{Key: key, Value: bson.D{bson.E{Key: types.AggregationPush, Value: expression}}}}
3030
}
3131

3232
func Avg(key string, expression any) bson.D {

builder/aggregation/bson_construction_test.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,9 @@ func TestSum(t *testing.T) {
3131
}
3232

3333
func TestPush(t *testing.T) {
34-
testCases := []struct {
35-
name string
36-
expression any
37-
want bson.D
38-
}{
39-
{
40-
name: "test push",
41-
expression: bsonx.NewD().Add("item", "$item").Add("quantity", "$quantity").Build(),
42-
want: bson.D{{Key: "$push", Value: bson.D{{Key: "item", Value: "$item"}, {Key: "quantity", Value: "$quantity"}}}},
43-
},
44-
}
45-
46-
for _, tc := range testCases {
47-
t.Run(tc.name, func(t *testing.T) {
48-
got := Push(tc.expression)
49-
assert.Equal(t, tc.want, got)
50-
})
51-
}
34+
t.Run("test push", func(t *testing.T) {
35+
assert.Equal(t, bson.D{{Key: "allItems", Value: bson.D{bson.E{Key: "$push", Value: "$item"}}}}, Push("allItems", "$item"))
36+
})
5237
}
5338

5439
func TestAvg(t *testing.T) {

0 commit comments

Comments
 (0)