title: Correct way to check who is the first to set a property in firebase firestore
body: <p>I'm creating a game using firebase firestore, and I need to tell which user started the game. 
  The idea that I had was to have a <code>startedByPlayer: string</code> property and use a transaction to update this property. If this property is already set, then eventually return false; otherwise, set this property with the current user and eventually return true.</p>
  
  <p>Since it's tough to test race conditions, I just wanted to make sure this was the right approach:</p>
  
  <pre><code>function tryToStartGame(player : Player) {
    const ref = gamesRef.doc("game");
    return db.runTransaction(function (transaction) {
      return transaction.get(ref).then(function (game) {
        if (!game.exists) {
          return false;
        }
  
        const { startedByPlayer: startedByUser } = game.data() as Game;
  
        if (!startedByUser) {
          transaction.update(ref, { startedByUser: player.id });
          return true;
        }
  
        return false;
      });
    });
  }
  </code></pre>