hopefully this isnt too hard to solve.
TLDR; Mostly the question is how to use async/await instead of then() syntax. More specifically how can I access docRef of the accessed document to return the id of that document along with all the other data?
I have a series of words objects that I retrieve from my firestore database.
Each of these words is an object that looks like this: {word: 'Apple', ref: 9IOGPbdfoURivbNfffwF, points: 10}
I iterate through each of these words to capture their full breakdown, provided at the destination of the ref. Each of these words, may or may not, include a translations sub-collection.
unfortunately, while I can successfully return wordData, that doc does not include the ID of the word. Rather, the ID I need is the ID of the word document itself. How can I write this so I have a word object that has all the word data + the ID of the doc using async/await syntax?
const data = Promise.all(
vocab.map(async (word: Word) => {
const wordRef = await word.ref.get();
const wordData = await wordRef.data(); <-- Problem is here.
const docRef = firebaseFirestore
.collection(`languages/${language}/vocabulary`)
.doc(wordData.id) <-- What i'm trying to do, but id isn't there
.collection('translations')
.doc(translationLanguage);
...
)
Thanks!