我想统计一下过go 一个月里按名字分组的人数.当我try 在Golang Mongo客户端中运行以下查询时.我得到的错误是:
error:
流水线阶段规范对象必须正好包含一个字段.
cond := &bson.D{
bson.E{Key: "$createTime", Value: bson.E{Key: "$gte", Value: time.Now().AddDate(0, -1, 0)}},
}
match := bson.D{{Key: "$match", Value: cond}}
group := bson.D{{Key: "$group", Value: bson.D{
{Key: "_id", Value: "$name"},
{Key: "count", Value: bson.D{{Key: "$sum", Value: 1}}},
}}}
cursor, err := col.Aggregate(ctx, mongo.Pipeline{match, group})
我不知道该怎么办?