Sign In Register

How can we help you today?

Start a new topic

Storing longest winning streak of a user

 Hi GameSparks team,


I need to count longest winning streak of user. I have a leader board set up to update monthly.


I store result of match in running collection with 3 variables: playerId, result, Date
Result is match’s result (W or L)


Date is a stored date of record but I don’t what I should do next.
I found in google:

http://www.sqlteam.com/article/detecting-runs-or-streaks-in-your-data


That should how to solve it by mysql but GameSpark use MongoDB. It’s quiet different.


I can use customCollection to find player by id and sort by date. After that I run for loop to count result value.
Do you have any better solution?


Thank you.


Hi Yomi Studio,


You can use aggregate to count the results.

For example

var wins = Spark.runtimeCollection("matchResults").aggregate({$group : {_id : "$result", num_wins : {$sum : 1}}});


Thanks

Katie

Thank you for your reply.

But we need to count longest winning streak. Your suggestion just only count number of win or lose match.

I think we should create a query to count of maximums consecutive records based on result.

Thanks 

Phuc


Login to post a comment