+ 2

How to get the corresponding firebase doc in javascript?

So far I'm able to retrieve every document in a specific collection, but how do I retrieve specific documents in a single collection? Let's say I have a form, and when the user submits the form a new document is created, I now need to retrieve that SPECIFIC document. How do I do that?

14th Feb 2021, 2:21 AM
Coder
Coder - avatar
1 Resposta
+ 3
I guess you are looking for this ``` var docRef = db.collection ("collection name").doc("doc name"); = docRef.get(). then ((doc) => { if (doc.exists) { console.log("Document data:", doc.data()); } else { // doc.data() will be undefined in this cas console.log("No such document! "); } }).catch((error] => { console.log("Error getting document:", error); }) ``` link https://firebase.google.com/docs/firestore/query-data/get-data#web
14th Feb 2021, 6:07 AM
Ananiya Jemberu
Ananiya Jemberu - avatar