title: Creating a leaderboard scenario on Cloud Firestore
body: <p>I'm playing with the recently introduced <a href="https://firebase.google.com/docs/firestore/" rel="nofollow noreferrer">Cloud Firestore</a> and I was wondering if it's possible to get a document's index in a collection to create a leaderboard. </p>
  
  <p>For example, let's say I want to retrieve a user's position in the leaderboard. I'd do something like this:</p>
  
  <p><code>db.collection('leaderboard').doc('usedId')</code></p>
  
  <p>There, I'd have a <code>rank</code> 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.</p>
  
  <p>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?</p>