Home > OS >  Second Firestore call in same function not querying
Second Firestore call in same function not querying

Time:06-14

I have this if statement in a function:

if(commander){
        if(outcome){            
            try { 
                await updateDoc(doc(db, 'commanders', commanderName), {
                    Wins:  commander.Wins   1,
                    Games: commander.Games   1,
                })
                return true;
            } catch(e){
                console.log(e);
            }
            try {
                await updateDoc(doc(db, 'players', playerName), {
                    Wins:  player.Wins  1,
                    Games: player.Games   1,
                })
                return true;
            } catch(e){
                console.log(e);
            }
        }

Before this if statement I have confirmed that both commanderName and playerName exist and hold valid values.

Updating commanders works correctly here, but it seems like the code just skips over updating players.

It may also be mentioning that elsewhere in the app this function works correctly:

export async function addPlayer(playerName: string) {
    await setDoc(doc(db, 'players', playerName), {
        Name: playerName,
        Games: 0,
        Wins: 0,
    })
}

So I know that the naming and syntax of the players update is correct.

What could be the issue here? Is there an easy way for me to try to debug this that I don't know about? I am using VS code if that matters. If you need any additional information please let me know.

CodePudding user response:

It's the return statement, "return true" - this exits ....

  • Related