Introduction to Firestore Collection and Document Basics

Welcome back! Previously, we explored Cloud Firestore, a flexible NoSQL database service designed for modern application development. In this session, we will focus on the essential building blocks of Firestore: collections and documents.

Firestore organizes data in a hierarchical structure. At the top level, you have collections, which are containers for documents. Each document holds data as key-value pairs, and documents can themselves contain subcollections, allowing for nested data organization. Unlike traditional relational databases, Firestore does not require you to define a schema in advance — each document in a collection can have a different structure, making it easy to adapt to changing data requirements.

Understanding how to structure your data using collections and documents is fundamental to building scalable and efficient applications with Firestore.

How Firestore Identifies and Organizes Documents

In Firestore, data is organized into collections and documents. A collection is a group of documents, and each document is a set of key-value pairs. Every document within a collection is uniquely identified by a document ID.

  • Collections: Collections are containers for documents. They do not store any data themselves but serve as namespaces for grouping related documents. For example, you might have a collection called users to store user profiles.

  • Documents: Documents are individual records within a collection. Each document has a unique ID within its collection, which can be automatically generated or specified manually. Document IDs are used to retrieve, update, or delete specific documents.

For example, consider a blogPosts collection where each document represents a blog post. Each document might have fields such as , , and :

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal