Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Labs

Creating Google Cloud Firestore Collections and Documents

You are tasked with developing a small web app to track a list of famous computer scientists. You want to store the details in a NoSQL document store so that you can interact with database records as JSON documents. If this app ever needs to scale, you need the database to be strongly consistent and globally available. To achieve this, you will create a Cloud Firestore database and connect to it with a Python Flask web app that runs in the Cloud Run serverless platform.

Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 30m
Published
Clock icon Apr 09, 2021

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Activate Cloud Shell and the Required APIs

    1. From inside the GCP dashboard, load the Cloud Shell terminal. Your project should already be active in the terminal (highlighted in yellow), but if it isn't, enter the following code using your project ID, which is located next to the Google Cloud Platform title at the top of the GCP dashboard:
      gcloud config set project <YOUR_PROJECT_ID>
      
    2. In the Cloud Shell terminal, using gcloud, activate the following APIs, which are required for this lab:
      • run.googleapis.com
      • cloudbuild.googleapis.com
      • containerregistry.googleapis.com
    3. Configure these settings for Cloud Run using gcloud config:
      • Set the region to us-east1
      • Set the platform to managed
  2. Challenge

    Create a Firestore Collection and Documents

    For this objective, we need to:

    1. Create a new Firestore database that is set to Native Mode and located in us-east1.
    2. Start a collection with the Collection ID of compscientists.
    3. Create the first document with the following information set on three lines:
    • Line one:
      • Field name: first
      • Field type: string
      • Field value: Ada
    • Line two:
      • Field name: last
      • Field type: string
      • Field value: Lovelace
    • Line three:
      • Field name: birthyear
      • Field type: number
      • Field value: 1815
    1. Create a second document for Alan Turing, born in 1912, using the same formatting from before for Field name and Field type, and update the Filed value with his information.
  3. Challenge

    Deploy and Test the Flask Application

    For this objective, you need your GCP project ID, which can be found next to the Google Cloud Platform title on the GCP dashboard:

    1. Clone the necessary git repo to get the Flask application code. This is our repo: https://github.com/linuxacademy/content-google-certified-pro-cloud-developer
    2. Change to the flask-firestore directory.
    3. Build the demo app using gcloud, --tag, gcr.io, and our project ID. Make sure to place it in the flask-firestore directory.
    4. Deploy flask-firestore to Cloud Run using --image, gcr.io, and our project ID. Make sure it is placed in our flask-firestore directory without having to be authenticated.
    5. Use the returned URL for your newly deployed app.
    6. Browse the URL and view the demo page listing the documents in the collection.
    7. Add a new computer scientist (perhaps yourself!) to the collection using the web app's form. Make sure you use proper names and a real year, as there is no exception handling in this web app.
    8. Check that the new document is listed both in the web app and in GCP.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans