I'm playing with the recently introduced Cloud Firestore and I was wondering if it's possible to get a document's index in a collection to create a leaderboard.
For example, let's say I want to retrieve a user's position in the leaderboard. I'd do something like this:
db.collection('leaderboard').doc('usedId')
There, I'd have a rank
field to display that user's position in the leaderboard. However, that means I'd have to create a Cloud Function to calculate users' position everytime their score changes. Considering Firestore charges by the number of CRUD operations, that could be really expensive.
Is there a better way to do it? Let's say define a query field (i.e. score), then get that document's index in the collection's array?