Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create test data for the Firestore Database
/ 50
Import test data into the Firestore Database
/ 50
Create test data for the Firestore Database
/ 50
Import test data into the Firestore Database
/ 50
Twelve years ago, Lily started the Pet Theory chain of veterinary clinics. The Pet Theory chain has expanded rapidly over the last few years. However, their old appointment scheduling system is not able to handle the increased load, so Lily is asking you to build a cloud-based system that scales better than the legacy solution.
Pet Theory's Ops team is a single person, Patrick, so they need a solution that doesn't require lots of ongoing maintenance. The team has decided to go with serverless technology.
Pet Theory hired Ruby as a consultant to help them transition to serverless. After comparing serverless database options, the team decides to use Cloud Firestore. Since Firestore is serverless, you don't need to provision capacity ahead of time, which means there is no risk of running into storage or operations limits. Firestore keeps your data in sync across client apps through real-time listeners and offers offline support for mobile and web, so you can build a responsive app that works regardless of network latency or internet connectivity.
In this lab, you help Patrick upload Pet Theory's existing data to a Cloud Firestore database. He works closely with Ruby to accomplish this.
This diagram gives you an overview of the services you use and how they connect to one another:
In this lab, you learn how to perform the following tasks:
This is an introductory-level lab. It assumes familiarity with the Google Cloud console and shell environments. Experience with Firebase is helpful, but not required.
You should also be comfortable editing files. You can use your favorite text editor or you can launch the code editor from the Cloud Shell toolbar:
Once you're ready, scroll down and follow the steps to set up your lab environment.
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the right is the Lab setup and access panel with the following:
Note that the lab timer is located near the top of the page, showing the remaining time.
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab setup and access panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab setup and access panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
Patrick's task is to upload Pet Theory's existing data to a Cloud Firestore database. He works closely with Ruby to accomplish this goal. Ruby receives a message from Patrick in IT...
|
Patrick, IT Administrator |
Hi Ruby, Our first step in going serverless is creating a Firestore database with Google Cloud. Can you help with this task? I am not very familiar with setting this up. Patrick |
|
Ruby, Software Consultant |
Hey Patrick, Sure, I would be happy to help with that. I'll send you some resources to get started, let's get in touch once you're done creating the database. Ruby |
Help Patrick set up a Firestore database in the Google Cloud console.
In the Google Cloud console, on the Navigation menu (), click Databases > Firestore, and then click Create a Firestore database.
Select Standard Edition.
For Security rules, select Open.
For Location type, click Region, and then select the lab region
On completion of the task, Ruby emails Patrick...
|
Ruby, Software Consultant |
Hey Patrick, Great work setting up the Firestore database! To manage database access, we will use a Service Account that has been automatically created with the necessary privileges. We are now ready to migrate from the old database to Firestore. Ruby |
|
Patrick, IT Administrator |
Hey Ruby, Thanks for the help, setting up the Firestore database was straightforward. I hope the database import process will be easier than it is with the legacy database, which is quite complex and requires a lot of steps. Patrick |
The new Cloud Firestore database is in place, but it's empty. The customer data for Pet Theory still only exists in the old database.
Patrick sends a message to Ruby...
|
Patrick, IT Administrator |
Hi Ruby, My manager would like to begin migrating the customer data to the new Firestore database. I have exported a CSV file from our legacy database, but it's not clear to me how to import this data into Firestore. Any chance you can lend me a hand? Patrick |
|
Ruby, Software Consultant |
Hey Patrick, Sure, let's set up a meeting to discuss what needs to be done. Ruby |
As Patrick said, the customer data is available in a CSV file. Help Patrick create an app that reads customer records from a CSV file and writes them to Firestore. Since Patrick is familiar with JavaScript, build this application with the Node.js JavaScript runtime.
lab01:To inspect the files, from the Cloud Shell toolbar, click Open in a new window (), and then click Open Editor (
) to launch the Cloud Shell Editor.
In Cloud Shell Editor, from the Start options, click Open Home Directory and then, click pet-theory > lab01 in the Explorer pane.
In the directory, you can see Patrick's package.json. This file lists the packages that your Node.js project depends on and makes your build reproducible, and therefore easier to share with others.
The following is an example package.json file:
Now that Patrick has his source code imported, he gets in touch with Ruby to see what packages he needs to make the migration work.
|
Patrick, IT Administrator |
Hi Ruby, The code I use for the legacy database is pretty basic, it just creates a CSV ready for the import process. Anything I need to download before I get started? Patrick |
|
Ruby, Software Consultant |
Hi Patrick, I would suggest using one of the many @google-cloud Node packages to interact with Firestore. We should then only need to make small changes to the existing code since the heavy lifting has been taken care of. Ruby |
To allow Patrick's code to write to the Firestore database, you need to install some additional dependencies.
pet-theory/lab01 directory and run the following commands to install the Firestore dependency:After the command completes, package.json automatically updates to include the new dependencies and resembles the following:
Next, review the pet-theory/lab01/importTestData.js script, which reads the CSV file of customers and writes one record in Firestore for each line in the CSV file. Patrick's original application resembles the following:
It takes the output from the input CSV file and imports it into the legacy database. Next, update this code to write to Firestore.
pet-theory/lab01/importTestData.js.To reference the Firestore API via the application, you need to add the dependency to the existing codebase.
pet-theory/lab01/importTestData.js, on a new line below const fs = require('fs'); (line 3), add the following require statement:Ensure that the top of importTestData.js looks like the following:
You can integrate with the Firestore database with a couple of lines of code. Ruby shared template code with you and Patrick for this purpose.
importTestData.js, on a new line below the closing brace } of the if (process.argv.length < 3) block (and above importCsv(process.argv[2]).catch(e => console.error(e));), add the following writeToFirestore function:This code snippet declares a new database object that references the database you created earlier in the lab. The function uses a batch process that processes each record in turn and assigns a document reference based on the identifier added. At the end of the function, the code commits (writes) the batch content to the database.
importTestData.js, replace the entire existing importCsv function with the following updated importCsv function (this updates if (e) to if (err), calls await writeToFirestore(records); instead of await writeToDatabase(records);, and retains await fs.createReadStream(csvFilename).pipe(parser); at the end of the function):importTestData.js, on a new line below const { Firestore } = require("@google-cloud/firestore"); (line 4 at the top of the file), add the following require statement:Ensure that the top of importTestData.js looks like the following:
importTestData.js, on a new line below const { Logging } = require('@google-cloud/logging'); (and above function writeToDatabase(records)), add the following constant variables to initialize the Logging client:try block of the importCsv function in importTestData.js, on a new line below console.log(`Wrote ${records.length} records`); (and above } catch (e) {), add the following code to write logs:importCsv(process.argv[2]).catch(e => console.error(e)); is still present as the final line at the bottom of pet-theory/lab01/importTestData.js and save the file. Your completed pet-theory/lab01/importTestData.js file should match the following:Now when the application code runs, it updates the Firestore database with the contents of the CSV file. The importCsv function takes a filename, parses the content line by line, and sends each processed line to the writeToFirestore function, which writes each new record to the customers collection.
Time to import some data! Patrick contacts Ruby about a concern he has about running a test with real customer data...
|
Patrick, IT Administrator |
Hi Ruby, I think it would be better if we don't use customer data for testing. We need to maintain customer privacy, but also need to have some confidence that our data import script works correctly. Can you think of an alternative way to test? Patrick |
|
Ruby, Software Consultant |
Hey Patrick, Fair point, Patrick. This is a tricky area, as customer data may include personal identifiable information, also called PII. I'll share some starter code with you to create pseudo customer data. We can then use this data to test the import script. Ruby |
Help Patrick get this pseudo-random data generator up and running.
faker library, which the script uses to generate fake customer data. Run the following command to update the dependency in package.json:pet-theory/lab01/createTestData.js and inspect the code. Ensure that it looks like the following:pet-theory/lab01/createTestData.js, to add Cloud Logging to the codebase, on a new line below const faker = require('faker'); (line 3), add the following require statement:Ensure that the top of createTestData.js looks like the following:
createTestData.js, on a new line below const { Logging } = require("@google-cloud/logging"); (and above function getRandomCustomerEmail(firstName, lastName)), add the following constant variables to initialize the Logging client:Ensure that the top of createTestData.js now looks like the following:
createTestData function in createTestData.js, on a new line below console.log(`Created file ${fileName} containing ${recordCount} records.`); (and above the closing brace } of the createTestData function), add the following code to write the logs:createTestData(recordCount); is still present as the final line at the bottom of pet-theory/lab01/createTestData.js and save the file. Your completed pet-theory/lab01/createTestData.js file should match the following:customers_1000.csv, which contains 1,000 records of test data:You should receive output similar to the following:
pet-theory/lab01/customers_1000.csv and verify that the script created the test data.Click Check my progress to verify the objective.
You should receive output similar to the following:
Run the following command to add the csv-parse package to your environment:
Over the past couple of sections you have seen how Patrick and Ruby have created test data and a script to import data into Firestore. Patrick now feels more confident about loading customer data into the Firestore database.
Test completed task
Click Check my progress to verify your performed task. If you have successfully imported sample test data into the Firestore Database, you will see an assessment score.
With a little help from you and Ruby, Patrick has now successfully migrated the test data to the Firestore database. Open up Firestore and see the results!
Type in /customers and press Enter.
Refresh your browser tab and you should see the following list of customers successfully migrated:
Throughout the course of this lab, you received hands-on practice with Firestore. After generating a collection of customer data for testing, you ran a script that imported the data into Firestore. You then learned how to manipulate data in Firestore through the Cloud Console.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated October 9, 2026
Lab Last Tested October 9, 2026
Copyright 2026 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We can notify you via email when it becomes available
Great!
We can contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one