Introduction to Firestore Data Manipulation

Welcome back! In our previous lessons, we've explored the essentials of Firestore, including its flexible data model based on collections and documents. Today, we will focus on how to add data to Firestore collections. You will learn how to create new documents, add multiple documents efficiently, and handle common scenarios when writing data.

For our examples, we'll use a students collection, where each document represents a student with the following fields: student_id, name, age, and major. Here's a quick look at the kind of data we'll be working with:

student_idnameagemajor
1Alice20Computer Science
2Bob22Mathematics

Let's get started by adding new student records and exploring how Firestore manages these data operations.

Creating a Document in Firestore

To add a new student, such as John, who is studying Physics, to the students collection, you create a new document with the relevant fields. In Firestore, you can either let Firestore generate a unique document ID or specify your own.

Here's how you can add John's details with a specific document ID (using student_id as the document ID):

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