I want to group some data with mongo-go-driver using aggregate, but the json result confused me, because the row key replaced with "Key" and and the real key become the "Key"s value
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)
Here is the result
[
[
{
"Key": "_id",
"Value": 15100
}
],
[
{
"Key": "_id",
"Value": 15101
}
]
]