Firestore Database

Firebase Firestore database overview

  • Cloud-hosted database

  • NoSQL database; data is stored as JSON

  • Changes made to the database are automatically synchronized for any other computer/phone (i.e. client) that is viewing data from the database

  • Firestore database documentation can be found here


Benefits

  • Simple data is easy to store in documents, which are very similar to JSON

  • Complex, hierarchical data is easier to organize at scale, using sub collections within documents

  • Requires less denormalization and data flattening.


Data Structure

  • data is stored in “documents” that contain fields mapping to values.

  • documents are stored in collections, which are containers for your documents that you can use to organize your data and build queries

  • Firebase’s Firestore database is structured like a JSON tree (think root and branches)

  • Data stored in a JSON tree is hierarchical (parent/child)

  • Properties names in the JSON tree can be used as keys (i.e. unique identifiers)

    {
      "users": {
        "alovelace": {
          "name": "Ada Lovelace",
          "contacts": { "ghopper": true },
        },
        "ghopper": { ... },
        "eclarke": { ... }
      }
    }
  

In the example above, we have a object that contains a list of users. Each user is represented as an object that has a property name or key. alovelace is the key that is tied to the object containing this user’s name and contacts.

  • As with regular JS Objects, keys must be unique