0
0
GcpHow-ToBeginner · 3 min read

How to Create Firestore Database on Google Cloud Platform

To create a Firestore database, go to the Google Cloud Console, select your project, then navigate to Firestore under the Databases section and click Create database. Choose the database location and mode (Native or Datastore mode), then confirm to set up your Firestore database.
📐

Syntax

Creating a Firestore database involves these main steps:

  • Project selection: Choose or create a Google Cloud project.
  • Firestore service: Access Firestore in the Cloud Console.
  • Create database: Click the button to start database creation.
  • Choose location: Select a region close to your users for better performance.
  • Choose mode: Pick Native mode for real-time updates or Datastore mode for legacy compatibility.
bash
gcloud firestore databases create --project=YOUR_PROJECT_ID --location=YOUR_REGION --type=firestore-native
💻

Example

This example shows how to create a Firestore database using the Google Cloud Console and the gcloud command-line tool.

bash
# Using gcloud CLI to create Firestore database
# Replace YOUR_PROJECT_ID and YOUR_REGION with your values
gcloud config set project YOUR_PROJECT_ID
gcloud firestore databases create --location=us-central1 --type=firestore-native
Output
Created Firestore database in project YOUR_PROJECT_ID at location us-central1 with Native mode.
⚠️

Common Pitfalls

  • Not selecting a project: You must select or create a Google Cloud project before creating Firestore.
  • Choosing wrong location: Pick a region close to your users to reduce latency.
  • Confusing modes: Native mode supports real-time updates; Datastore mode is for legacy apps.
  • Trying to create multiple databases: Each project can have only one Firestore database.
bash
# Wrong: Trying to create multiple databases in one project
# This will fail because only one Firestore database per project is allowed
gcloud firestore databases create --location=us-central1

gcloud firestore databases create --location=europe-west1

# Right: Use one database per project and configure collections inside it
📊

Quick Reference

Summary tips for creating Firestore database:

  • Always select the correct Google Cloud project.
  • Choose the database location near your users.
  • Pick Native mode for new apps needing real-time features.
  • Use gcloud CLI or Cloud Console for setup.
  • Remember one Firestore database per project.

Key Takeaways

Create Firestore database by selecting your Google Cloud project and using the Cloud Console or gcloud CLI.
Choose the database location close to your users for better performance.
Select Native mode for real-time updates or Datastore mode for legacy compatibility.
Each Google Cloud project can have only one Firestore database.
Use gcloud commands or the Cloud Console UI to complete the setup easily.