Introduction

Welcome to the fifth lesson in our course. In this lesson, we will focus on how to update and delete items in a NoSQL database. Being able to modify and remove data is essential for maintaining accurate and up-to-information in your applications. You will learn how to update specific fields in existing records, delete individual records, and efficiently remove multiple records at once. These skills are fundamental for managing data in any NoSQL environment.

Updating Fields in Firestore Documents

To update data in Firestore, you can modify specific fields within a document without replacing the entire document. This is done by referencing the document you want to update and specifying the fields and new values.

Here is an example of updating the content field of a document in the UserPosts collection, where the document ID is john_post1:

This operation changes only the specified field, leaving the other fields in the document unchanged. You must provide the correct document reference to ensure the update is applied to the intended item.

Deleting Documents in Firestore

To remove a document from a collection in Firestore, you use the delete() method on the document reference. This will permanently remove the document and all its fields from the database.

Here is how you would delete a document with the ID from the collection:

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