【发布时间】:2019-06-25 09:53:23
【问题描述】:
我想用 mongo-go-driver 使用聚合对一些数据进行分组,但是 json 结果让我很困惑,因为行键替换为“键”,而真正的键变成了“键”的值
var result primitive.A
pipeline := mongo.Pipeline{{{"$group", bson.D{{"_id", "$nis"}}}}}
cursor, err := db.NilaiUH.Aggregate(context.TODO(), pipeline)
cursor.All(context.Background(), &result)
json.NewEncoder(w).Encode(&result)
这是结果
[
[
{
"Key": "_id",
"Value": 15100
}
],
[
{
"Key": "_id",
"Value": 15101
}
]
]
【问题讨论】: