Course contentsShow
← Computer Science
Lesson 1721 of 2,87239. NoSQL and Modern DatabasesFree lesson

CRUD Operations in Document Databases

Creating, reading, updating, and deleting documents using basic query operations and document identifiers.

CRUD Operations in Document Databases

You'll learn: How to create, read, update, and delete documents in a document database using identifiers and basic query operations.

What Are CRUD Operations?

CRUD stands for Create, Read, Update, Delete—the four fundamental operations for managing data in any database. In document databases, these operations work directly with JSON-like documents rather than rows in tables. Each document has a unique identifier (like _id in MongoDB) that serves as its primary reference point.

Think of a document database like a filing cabinet where each folder (document) has a unique label (identifier). You can add new folders, pull them out to read, modify their contents, or remove them entirely.

The Four Basic Operations

Create: Inserting a new document into a collection. You provide the document's structure, and the database typically auto-generates an identifier if you don't specify one.

Read: Retrieving documents by their identifier or by matching specific fields within the document structure. This is how you query your nested JSON data.

Update: Modifying existing documents, either by identifier or by matching criteria. You can replace entire documents, update specific fields, or modify nested properties deep within the document hierarchy.

Delete: Removing documents by identifier or criteria. Once deleted, the document and its nested data are gone (unless you have backups or soft-delete strategies).

Why Document Identifiers Matter

Every document needs a unique identifier so the database can locate it instantly—similar to how a primary key works in relational databases. These identifiers enable O(1) lookups and make updates/deletes precise. Without them, you'd have to scan through field values, which is slower and less reliable.

Key Takeaway: CRUD operations in document databases manipulate JSON-like documents using unique identifiers and query patterns that respect the nested, schema-flexible structure of documents.