Firestore is a cloud database allowing us to store, sync, and query data for cross-platform applications.
To start using Firestore, we must be familiar with creating a database on Firebase.
Step 1
Sign in to Firebase.
Create a project.
Name it something meaningful (this name will help in the following steps).
Proceed further by clicking the "Continue" button.
Once the project is created, we’ll be directed to the project's home page, where we can set up the database for our project. The slideshow below illustrates how to set it up:
Step 2:
To create a database on Firebase, locate "Firebase Database" in the left panel.
We see an option to "Create Database" when we click it.
Next, we’ll be asked to open the project in “Production” or “Test” mode.
For now, open this in test mode, and on the next screen, click the “Enable” button.
Once we’ve completed the steps above, we’ll see an empty database created on the cloud Firestore.
Let's see how we can add this Firestore database to our application.
Step 1:
The first step to adding Firestore to any application is to generate a private key.
To do this, click the "⚙️" in the left panel.
Click "Project settings" then "Service accounts." The “Generate new private key” button will be at the bottom.
Choose a language from the given options: Node.js, Java, Python, and Go. A .json
file with our project’s name will be downloaded containing the project-specific configurations.
Copy and paste the content of the JSON file above into the project's JSON file.
By now, we have our private key, which we’ll use to store and access data from Firestore.
Click the web icon, and a new window will open, asking us to enter our project’s name. Follow the steps as guided, and the Firestore for our web application will be created.
As done previously, go to “Project settings” and scroll down in the “General” section to see the firebase configuration for the web application.
By copying the contents of the firebaseConfig
, we can connect our application with Firestore.
Free Resources