Multiple data write using 'set()' on Firestore

Hi!

I need help on Firebase.

I need to save my data to Firestore, consisting the following setup:

  1. Orders collection - sort of parent table
  2. OrderDetails collection - sort of child/children table

These collections are not joined/referenced together, they are created separately as flat collections.

My goal is to write the Order document first and get its documentID and then use it to write the succeeding OrderDetails documents.

I have tried using then() after the first write for the Order document, but writing documents for the OrderDetails inside then() is not working.

Any suggestion, links to topics is appreciated. Thanks!