res, err := userGamesCollection.Distinct(context.Background(), "gametype", bson.M{})
fmt.Println(res)
fmt.Println(err)
for _, gametype := range res {
fmt.Println(gametype)
pipeline := []bson.D{
bson.D{{"$match", bson.D{{"gametype", "11"}}}},
bson.D{{
"$group", bson.M{
"_id": bson.M{
"date": bson.M{
"$dateToString": bson.M{
"format": "%Y-%m-%d",
"date": "$created",
},
},
"gametype": "$gametype",
},
"count": bson.M{"$sum": 1},
}}},
bson.D{{"$sort", bson.M{"_id": 1}}},
}
opts := options.Aggregate().SetMaxTime(5 * time.Minute)
cur, err := usersCollection.Aggregate(context.Background(), pipeline, opts)
defer cur.Close(ctx)
fmt.Println(cur)
fmt.Println(err)
var results []bson.M
cur.All(ctx, &results)
fmt.Println(results)
}