I am building a simple app that has a table connected to a firestore collection.
New rows need to have a special ID, that is the max of the current ID + 1.
I thought this would be simple, but I am having a challenge here.
This is my create new row query (createGuessWhatQuestion):
The document ID is based on another query that retrieves the maximum ID +1 (getGuessWhatQuestionNewId).
After adding a new row I triggger the JS query to create the next ID on the success handler.
This is the code for creating a new ID:
Now the problem is that this doesn't always work. Although I am updating the query from firestore before generating the new ID (await getGuessWhatQuestions.trigger();), sometimes the new added row is still not there.
What I think it's happening is that my createGuessWhatQuestion triggers the success handler, before making sure the new row was properly added to the firestore database.
Is this possible? Should I be doing this another way?