What is Cloud Firestore?
Firestore is also called Cloud Firestore. Cloud Firestore is provided by Firebase and Google Cloud. It is a realtime database resides in the google cloud. It is very flexible, scalable, easy to use, NoSQL cloud database which is use to store the data for web app, mobile app, server-side or client-side development.
Cloud Firestore provides offline support for mobile and web apps.
You can integrate Cloud Firestore with other Firebase, Cloud Functions, and Google Cloud products.
Cloud Firestore has various capabilities like Flexibility, Expressive querying, real-time updates, Offline
support, Designed to scale, etc.
How does Cloud Firestore database work?
Cloud Firestore is a cloud database means Cloud Firestore is a cloud-hosted, NoSQL database. The web app, mobile app can access this database directly via native SDKs. Cloud Firestore provide support in many programming languages like Node.js, Java, Python, Unity, C++, and Go SDKs.In this Cloud Firestore database, you need to store data in the form of documents that contain fields, and they are mapped to its values. The documents are stored in collections just like MongoDB. Cloud Firestore provides the facilities to create sub-collections within documents and you can build hierarchical data structures using this technique. The Cloud Firestore data structure model supports whatever data structure best suits your app.
Querying in Cloud Firestore is easy and it is flexible, expressive, and efficient. The advantages of this Cloud Firestore database are It creates shallow queries to get the data at the document level and it has no need to retrieve the entire collection or also no need to get retrieve any nested sub-collections.
You can add real-time listeners to your Cloud Firestore database. If you added real-time listeners to your app then it notifies you with a data snapshot. The listeners will receive only the new changes. whenever the data your client apps are listening to changes.
You can protect your Cloud Firestore database with additionally using Cloud Firestore Security Rules and Firebase Authentication. This security tool is for Android, Apple platforms, and JavaScript. You can also integrate Identity and Access Management (IAM) for server-side programming languages.
What is Firebase Admin SDK?
The Firebase Admin SDK is used to interact with Firebase to perform actions like:1. Cloud Firestore database connection and perform read and write real-time data with admin privileges
2. To send Firebase Cloud Messaging messages programmatically
3. Generate Firebase auth tokens and verify Firebase auth tokens
4. Interact with other Google Cloud Platform resources
5. Create Admin Console
How to use Firebase Admin SDK?
let's see how we can use the Firebase Admin SDK in our node projects. here we will write some codes to connect Firebase Admin SDK to Firestore and will update the database.Step 1: Get the service account credentials
You need service account credentials which you can download from the firebase console under the firebase admin SDK tab. Select/Click on “Generate New Private Key”, this downloads a JSON file containing the service account credentials. Add these credentials to your project directory with the name "serviceAccountKey.json". Add this to your project's directory now this service account JSON file contains sensitive information including your service account's private encryption key. Remember to keep it confidential, Never add it to version control, never put it in a client app, and never store it in a public repository.Steps to create service account credentials:
Goto the URL https://console.firebase.google.com -> Select Project -> Click on the setting icon from the top left corner -> Select "Project Settings" -> Click on "Service Accounts" from the available nav bar -> Select firebae Admin SDK -> Click on "Generate new private key" -> Click on "Generate Key"
See the screenshot for more help:
What is GCP Firestore and Firebase Admin SDK? Integrate Firebase Admin SDK with NodeJS
Step 2: Install Firebase Admin
If you want to use Firebase Admin SDK then you need to install firebase-admin npm package in your project dependencies by using the below commands.
or
Step 3: Write the codes to set the data into firestore
Create a file with name "index.js" and write the below codes.index.js
Step 4: Run the app
Now, its time to run the app using below command. and see the firestire database.
See the screenshot for more help:
What is GCP Firestore and Firebase Admin SDK? Integrate Firebase Admin SDK with NodeJS
Step 5: Write the codes to fetch the data from firestore
You can add the below codes into the index.js file to fetch the data accordingly.
Conclusion:
In this article, we learned about the Firestore.What is Cloud Firestore?
How does the Cloud Firestore database work?
What is Firebase Admin SDK?
How to use Firebase Admin SDK?
How to get the service account credentials?
How to install Firebase Admin?
Write the codes to set the data into firestore
Write the codes to fetch the data from firestore
Related Keywords:
What is Cloud Firestore?
How does Cloud Firestore database work?
What is Firebase Admin SDK?
How to get the service account credentials?
Write the codes to set the data into firestore
Write the codes to fetch the data from firestore
Support our IDKBlogs team
Creating quality content takes time and resources, and we are committed to providing value to our
readers.
If you find my articles helpful or informative, please consider supporting us financially.
Any amount (10, 20, 50, 100, ....), no matter how small, will help us continue to produce
high-quality content.
Thank you for your support!
Thank you
I appreciate you taking the time to read this article. The more that you read, the more things you will know. The more that you learn, the more places you'll go.
If you’re interested in Node.js or JavaScript this link will help you a lot.
If you found this article is helpful, then please share this article's link to your friends to whom this is required, you can share this to your technical social media groups also.
You can follow us on our social media page for more updates and latest article updates.
To read more about the technologies, Please
subscribe us, You'll get the monthly newsletter having all the published
article of the last month.