5. Inserting, Updating, and Deleting Documents

Overview

This chapter introduces you to the core operations in MongoDB, namely inserting, updating, and deleting documents in a collection. You will learn how to insert a single document or a batch of multiple documents into a MongoDB collection. You will add or autogenerate an _id field, replace existing documents, and update specific fields in the documents of an existing collection. Finally, you will learn how you can delete all or delete specific documents in a collection.

Introduction

In previous chapters, we covered various database commands and queries. We learned to prepare query conditions and use them to find or count the matching documents. We also learned to use various conditional ...

Get MongoDB Fundamentals now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.