Amazon.co.uk Widgets

Log in

X
Setting up Firebase Firestore

A Beginner's Guide to Firebase Firestore for App Developers

Firebase Firestore is a flexible, scalable database built for mobile and web applications. It supports hierarchical data structures, expressive queries, realtime updates, offline support, and seamless integration with other Firebase and Google Cloud products. If you are building a mobile app and need a reliable cloud database, Firestore is an excellent choice.

This article walks you through the steps required to create a Firebase project, set up a Firebase Firestore database, add data, and read data from it.

TL:DR –  This article goes through the setup steps required to get it going.

What Is Firebase Firestore?

Firebase Firestore is a horizontally scaling, document-model NoSQL database hosted in the cloud. Unlike traditional relational databases, Firestore organises data into collections and documents, making it well suited to the dynamic, nested data structures common in mobile applications.

Key features include:

  • Realtime updates: Your app receives instant notifications when data changes.
  • Offline support: Data is cached locally so your app remains functional without a network connection.
  • Scalability: Firestore scales automatically to handle growing user bases.
  • Integration: It works seamlessly with other Firebase and Google Cloud products.

Step 1: Create and Set Up a Firebase Project

Before you can use Firestore, you need a Firebase project. Follow these steps to get started.

1.1 Create a New Firebase Project

  1. Go to the Firebase Console.
  2. Click Add project.
  3. Enter a name for your project. Take note of the project ID, or click the Edit icon to set a custom one.
  4. Click Continue.
  5. Optionally, enable Google Analytics for your project.
  6. Click Create project.

Firebase Console Setup screen shot

Enable Google Analytics (Optional).

Firebase Console Enable Analytics screen shot

Firebase console (Optional).

Firebase Console screen shot

Enable anonymous guest accounts

Firebase Console screen shot

Firebase Firestore

Firebase Firestore is specifically designed to allow you to store and sync app data at global scale.

See also : Explainer video, Documentation, Firebase Firestore website.

Check your email for confirmation

If all went well you'll get a nice confirmation email too.

"Welcome to Firebase! You're now part of a community of hundreds of thousands of developers using Firebase to build better mobile and web apps, as well as grow their businesses. Congrats on creating your first project."

Create Database

Firebase Console 'Create database' screen shot

Start in test mode. Note the warning - this database will need to be secured for production use.

Firebase Console screen shot

Firebase Firestore The locations cannot be changed so if geographic location is important for example for data protection then it is important to pick an appropriate one. This is an app for the UK so europe-west2 was chosen as it is in London.

 

Enable Anonymous Authentication

Anonymous authentication allows your application to silently sign users in without requiring them to create an account. This is useful for letting users interact with your app before committing to registration.

  1. In the Firebase console, handle to the Authentication section under Build.
  2. Click Get started.
  3. Select the Anonymous sign-in provider and enable it.

Create a Firebase Firestore Database

With your Firebase project ready, you can now create a Firestore database.

  1. In the Firebase console, handle to Firestore Database under the Build section.
  2. Click Create database.
  3. Select Start in test mode.
Important: Test mode allows open read and write access to your database. This is acceptable for development, but you must configure proper security rules before deploying to production.
  1. Choose a Firebase Firestore location. This setting is permanent and cannot be changed later. If data residency or geographic proximity matters for your use case, choose carefully. For example, if your app serves users in the United Kingdom, selecting europe-west2 (London) is a sensible choice.
  2. Click Enable.

Your Firestore database is now live and ready to use.

Firebase Console screen shot

Step 3: Add Data to Firestore

Firestore stores data as documents organised into collections. A document is a set of key-value pairs, and a collection is a container for documents.

Adding Data via the Firebase Console

The simplest way to add data when getting started is through the Firebase console:

  1. Open your Firestore database in the console.
  2. Click Start collection and give it a name, such as restaurants.
  3. Add a document by providing a Document ID (or letting Firestore generate one automatically).
  4. Add fields to your document, such as name, category, and rating, along with their respective values.
  5. Click Save.

Adding Data Programmatically

In a Flutter application, you can add data to Firestore using the cloud_firestore package.

Step 4: Read Data from Firestore

Reading data from Firestore can be done as a one-time fetch or as a realtime stream that updates your UI whenever the data changes. Using a stream is the recommended approach for mobile apps because it keeps your UI in sync with the database without requiring manual refresh calls.

Step 5: Set Up the Firebase CLI

The Firebase Command Line Interface (CLI) is required to use Firebase development tools, including deploying security rules and hosting assets.

Note: The Firebase CLI is installed via npm, which introduces a dependency on Node.js. Before adding any third-party dependency to your project, it is good practice to review its maturity, licensing, and rate of change, and to maintain a record of all external dependencies along with any associated cost implications.

Install the Firebase CLI

Run the following command in your terminal:

  • Install the CLI using npm -g install firebase-tools
  • Verify the installation using firebase --version. It should return the version number if successful.
  • Authorize the Firebase CLI by running firebase login

     

Follow the prompts to sign in with your Google account. Once authorised, close the success window in your browser.

Firebase CLI Authorisation screen shot

Summary

Here is a quick recap of the steps covered in this article:

  1. Create a Firebase project in the Firebase console.
  2. Enable Anonymous Authentication.
  3. Create a Firebase Firestore database in test mode, selecting an appropriate geographic location.
  4. Add data to Firestore via the console or programmatically using the cloud_firestore package.
  5. Read data using one-time fetches or realtime streams.
  6. Install and configure the Firebase CLI.
  7. Associate your app with your Firebase project.

Further Reading