Skip to content

Commit 8e5c906

Browse files
committed
fix count bug
1 parent 41f0bb8 commit 8e5c906

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

engine/aggregate.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func aggrigate(query gjson.Result) string {
117117

118118
switch opr.Str {
119119
case "$count":
120-
counted := count(fld.Str, data)
120+
counted := count(_id, data)
121121
for _id, count := range counted {
122122
mapData[_id], _ = sjson.Set(mapData[_id], key.Str, count)
123123
}
@@ -597,16 +597,7 @@ func average(_id string, field gjson.Result, records []string) (mp map[string]fl
597597
return mp, nil
598598
} // average
599599

600-
func countField(field string, records []string) (mp map[string]int) {
601-
602-
mp = map[string]int{}
603-
for _, record := range records {
604-
mp[gjson.Get(record, field).Str]++
605-
}
606-
607-
return mp
608-
}
609-
600+
// count counts entities in collection by provid field
610601
func count(field string, records []string) (mp map[string]int) {
611602

612603
mp = map[string]int{}

0 commit comments

Comments
 (0)