Read a document from Firestore Database in Angular

Firestore is a commonly used database for Mobile, PWA and many more real time apps. Reading data from Firestore sometime becomes time taking for beginners. I will here explain how you can read a document from Firestore Database in Angular.

I am assuming you have created a Firebase Application and have done the Firebase Configurations. If not, click here to create.

Follow the steps:

1. Install @angular/fire/firestore

Run command npm i @angular/fire/firestore to install Firestore module in Angular project. Once installed, add that into the app.module.ts file.

2. Get document in component

Import Firestore package in component:

Create Instance in Constructor:

Apply code to fetch data: (Note: Replace collectionName and documentId with your real collection name and document id before running the code)

You will see your document are displayed at Browser Console.

Conclusion

That’s it. Write me up for any query you are having. In this article we learnt about how to read a document from firestore database in Angular. Firestore is a NoSQL database mainly used by mobile apps.

Leave a Reply

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