Hi @Pavel_Duchovny
Yes. There is a score field for each quiz solved and each player has a document with the quizzes array holding those scores.
I modified the schema so that there is a score field ONLY for the finished quizzes.
So I check if { $exists: true } on the score field to get the number of players who finished the quiz and I no longer need the done field to do that.
I calculate the ranking of a player on a certain quiz based on the score field on the quiz.
To get the correct ranking I found that I have to select only distinct scores so that multiple players having the same score would have the same ranking. Unfortunately, the distinct made the query even slower!
Now even the quizzes.0.score index that I mentioned before is making the query slightly slower than without it.
I tried the partial filter expressions and it doesn’t make sense for my case as any player that I’m getting the rank for could have a score of zero which means the filter would be { $gte: 0} which basically selects the whole collection. I tried it and it was slower than without index.
For now, I no longer use any index as this seems the fastest for my case.
Please update me if you have other suggestions.
Thanks in advance
Regards
Michael