How I get the generated document ID of a collection in Firestore?
Asked
Active
Viewed 47 times
0

ChrisGPT was on strike
- 127,765
- 105
- 273
- 257
-
Do you want to get the existing doc id or do you want to get the doc id when you insert a new document? – udoyhasan Apr 20 '22 at 11:56
1 Answers
0
If you want to get the id of a Firestore doc, call doc.id
. This is not in doc.data
and confused me as well.
const docs = await getDocs(collection(db, 'collection_name'));
docs.forEach((doc) => {
console.log(doc.id);
});

JeffreytheCoder
- 74
- 5