golang操作mongoDB的group多个字段的命令,怎么取group字段life和domain的值呀?
pipe := mongoDB.C("doc").Pipe([]bson.M{{"$match": bson.M{"date": curDay,}}, {"$group": bson.M{"_id": bson.M{"life": "$life", "domain": "$docdomain"}, "total": bson.M{"$sum": 1}}}})
resp := []bson.M{}
err = pipe.All(&resp)
if err == nil {
for _, row := range resp {
fmt.Println(row["_id"]) //这句是有结果的 map[life:xxxx,domain:xxxx]
fmt.Println(row["_id"]["life"] //报错,要怎么数据转换?
}
}
有疑问加站长微信联系(非本文作者)