i have database events have happened in game. trying retrieve information how many unique players have started level. use piece of code that:
heh = list(db.events.aggregate( [ { "$match": {"status": 'start'}}, {"$group": {"_id": "$eventname", "players": {"$sum": 1}}}, ])) print(heh)
but getting information how many times level started. how can change code right info? unique users have unique "uid".
try this.. $addtoset adds unique records , count records in array
db.events.aggregate( [ { "$match": {"status": 'start'}}, {"$group": {"_id": "$eventname", "players": {"$addtoset": "$uid"}}}, {"$project": {"_id": 1, "count": {"$size": "$players"}}} ])
db.test1.aggregate( [ { "$match": {"status": 'start'}}, {"$group": {"_id": "$eventname", "players": {"$addtoset": "$uid"}}}, {$unwind:"$players"}, {$group:{_id:"$_id",count:{$sum:1}}} ] )
Comments
Post a Comment