How can I get the document ID and store it in field, such as the document ID marked in red, and store in post_pid
Asked
Active
Viewed 1,187 times
0
-
Can you share the code you use to write the doc? – Renaud Tarnec Jun 05 '22 at 15:06
-
[Your query is entertained here...](https://stackoverflow.com/questions/62968486/how-do-i-get-documentid-of-a-firestore-document-in-flutter) – Hammad Ali Jun 05 '22 at 15:10
1 Answers
0
You can do something like this while adding your data.
const postDocRef=firebaseClient.firestore().collection('post_details').doc();
await postDocRef.set({
post_pid: postDocRef.id,
// ....rest of your data
});
We get a document reference first and then we get the id
property.

wick3d
- 1,164
- 14
- 41