I am trying to get aggregated values from a mongo collection using bson and Golang where the field used in Golang is of type map[string]uint32
.
This is the struct am using and the field is Csat
.
type Conversations struct {
ID bson.ObjectId `bson:"_id"`
Csat map[string]uint32 `bson:"csat"`
}
The output using bson should be in key value pairs, these are some examples I tried but did not work,
1.
bson.M{
"csat["1"]": bson.M{
"$sum": bson.M{"$cond": []interface{}{bson.M{"$eq": []interface{}{"$score", 1}}, 1, 0}},
},
"csat["2"]": bson.M{
"$sum": bson.M{"$cond": []interface{}{bson.M{"$eq": []interface{}{"$score", 2}}, 1, 0}},
}
2.
bson.M{
"csat": bson.M{
"1": bson.M{
"$sum": bson.M{"$cond": []interface{}{bson.M{"$eq": []interface{}{"$score", 1}}, 1, 0}},
},
"2": bson.M{
"$sum": bson.M{"$cond": []interface{}{bson.M{"$eq": []interface{}{"$score", 2}}, 1, 0}},
},
}
}
I expect it to store it like {"csat": {"1": 3}, {"2": 2}, ...}
where 3 and 2 could be values of the keys.
If anyone has done something like this before, can you please help me out?
Thanks.