Sometimes, we want to query Firestore database for document ID with JavaScript.
In this article, we’ll look at how to query Firestore database for document ID with JavaScript.
How to query Firestore database for document ID with JavaScript?
To query Firestore database for document ID with JavaScript, we call the doc method.
For instance, we write
const book = db.collection("books").doc("fK3ddutEpD2qQqRMXNW5").get();
to get the books collection with
db.collection("books")
Then we call doc to get the entry from the books collection with ID 'fK3ddutEpD2qQqRMXNW5'.
Finally, we call get to return the object with the given ID.
Conclusion
To query Firestore database for document ID with JavaScript, we call the doc method.