Categories
JavaScript Answers

How to query Firestore database for document ID with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *