Multiple queries that are dependent on each other

Hey, so I'm learning retool. I'm working on the project where there is a lot of referenced data. I'm using firebase. So for example I want to create a user:

A user can have multiple emails so he can can add multiple emails.

When I create the user I want the emails to be created first get all the Ids put them in the array and save in the user collection

example:
user-1: {
name: "Harris Mir",
email: ["0MtLZFbUyj08zHY2Lc3A" , "3PPUsiwROnDiKeJEknnx"]
}

If you have any suggestions to how to do this. It will be very helpful

@harrisbytemage Welcome to the forum!
It depends on how your user is entering that information: a form?

If you read the following doc, you should be able to use Temporary state to allow you to gather all emails in a variable and then take that one value and put it in a query to insert or post - Temporary state

@ScottR, thanks for the response. Yes I'm using a a form. Can I just run one query which is comprised of many queries meaning I can get the value of the email from form and then call one query to save it and it returns me an id of the email document and i can put that in an array run another query to save the user. Can i do something like that?

Yes, you can use Event handlers when each query Succeeds call the next one

Thank @ScottR for engaging with me in this but sorry if i'm missing something here. I'm still learning. How to get the id of document i just created so that i can use it in another query? I read something about transformers

I am not familiar enough with firebase but I know that in postgres there are functions to get an ID from the most recent record inserted into the db....

Also, unless I am missing something as well, what other actions are you trying to perform...

Step 1...
Step 2...

screenshots and code will help me help you as well

I know the email is select just ignore it for a minute

So here how it goes

  1. I enter all the data
  2. I want the email to be stored in another collection/table and i get the id and put it in an array and save the user

I think you will need to perform an action for the email field once it is populated - if you need to generate an ID for each email address you can use uuid.v4();
Then take all of the information and Add Candidate.
I would use a single text field with a button to "add" email to a temp state with a generated UUID for each email and then when clicking Add Candidate, you can use the temp state variable in the insert into Firebase....
insert field1, field2, field3,..... {{tempStateVariableName.value}}

Thank you so much, means a lot