How to create a database in Cloud Firestore?
Getting started with Cloud Firestore may seem challenging, but with Google Cloud tools, the process can be manageable and efficient. In this article, you will learn how to create a document database in the Google Cloud Platform (GCP) console.
Where do I access Firestore in Google Cloud?
To open Firestore, go to the GCP console. In the top left corner, you will find the hamburger menu. From there, look for the Firestore option, which will allow you to create a document database.
What is the correct mode of operation for my database?
In Cloud Firestore, there are two modes of operation: native mode and datatore mode. This is a crucial aspect, since, once selected, you will not be able to change it. Therefore, make sure you choose the one that best suits your project. In this guide, we will opt for the native mode.
How do I select the location of my database?
The location of your database is an important factor. You can decide between a multi-regional or regional scope, depending on the needs of your project. In this case, we chose to locate our database in Northern Virginia.
How to load data into Cloud Firestore?
Loading data into Firestore is a simple process once you have your database created. You will learn how to use JavaScript scripts for Node.js, designed to make loading data easy.
What scripts do I need?
- createTestData.js: This script generates a dummy file of contacts that we will use to load data into Firestore.
- importTestData.js: This script reads the created test file, connects to Firestore and loads the information into a collection called "customers".
Running the scripts
Before you start, make sure your database and collection are created:
node createTestData
ls
node importTestData customers_5.csv.
At the end of the execution, the dummy data will have been loaded into your Firestore "customers" collection.
How can I visualize and filter the data?
In the GCP console, after refreshing the screen, you should be able to see the "customers" collection full of fictitious documents. You can perform various filters, such as by identifier or by email, to visualize the information more efficiently.
What's next?
Now that you have a database with a collection of customers, it is the ideal time to develop your application. This app should connect to the database you have created, which will open up a whole world of possibilities.
With this knowledge of Cloud Firestore, the limit is set by your creativity. Keep practicing and experimenting to strengthen your database management skills. גשאב הוּב דִּבְרֵי תמיֱד.
Want to see more contributions, questions and answers from the community?