Firebase Cloud Firestore

⚠️ Register your Free GCP Coupon from the instructor!

⚠️ ⚠️ You must use your IUT Google account for you coupon to work ⚠️ ⚠️

https://www.iut-acy.univ-smb.fr/ 👉 Intranet 👉 Resources Informatiques 👉 Offres Logiciel 👉 Plateforme Google

1 Adding admin access to Firestore to express

  1. https://console.firebase.google.com

  2. Sign in to your IUT google account

  3. “Add project”

  4. Give your project a unique name, i.e. “weather”.

  5. Disable Google Analytics (we won’t be using them). disable google analytics

  6. Click “Create project”.

  7. In the firebase web console, navigate to “Firestore Database” and click “Create Database”

    create database

  8. Choose “Start in test mode”. ⚠ Note the security warning: your database is open for anyone to read/write! Click “Create project”.

    security rules

  9. Use the default nam5 (us-central) location and click “Done”: firestore location

  10. Click on “Start collection”

  11. Give the collection the name cities and click “Next”.

  12. Collections only exist if they contain documents. Therefore, we are required to create an initial document.
    • We will use the city name as the.
    • The document should store enough information to show some the most recent searches and a count.
    • Click “Save” to store the first document

    first document

  13. Optionally add some more documents.

  14. In the Firebase console, click on the setting gear then “Project settings”

    settings

  15. Click on the “Service accounts” tab, click “Generate new private key” and store the key in the root of your project. Finally, click the button to copy the code snippet and paste it to your app.js file in your weather project.

    firebase add service acount

  16. Add firebase-admin to your project:
    npm install --save firebase-admin
    

Now we can access the admin Firestore API:

1
const citiesCollection = admin.firestore().collection('cities');

Be sure to also read the Firestore Documentation.

Exercise 1.1: Update an associated city whenever a weather query occurs.