Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Second Firestore call in same function not querying

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

It’s the return statement, "return true" – this exits ….

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading