MongoDB supports following CRUD operations:
- Create
- Read
- Update
- Delete
In MongoDB, CRUD stands for Create, Read, Update, and Delete. These are the basic operations that can be performed on the documents in a MongoDB database.
- Create (C): This operation involves the insertion of new documents into a MongoDB collection. In MongoDB, a document is a set of key-value pairs, similar to a JSON object.Example:
db.collection.insertOne({ key1: value1, key2: value2, ... });
- Read (R): Reading or querying data from a MongoDB collection. MongoDB provides flexible query capabilities to retrieve specific documents or data based on various criteria.Example:
db.collection.find({ key: value });
- Update (U): Modifying existing documents in a MongoDB collection. This can involve updating specific fields or replacing entire documents.Example:
db.collection.updateOne({ key: value }, { $set: { newKey: newValue } });
- Delete (D): Removing documents from a MongoDB collection based on specified criteria.Example:
db.collection.deleteOne({ key: value });
These CRUD operations are fundamental to interacting with and managing data in MongoDB databases. They provide a simple and powerful way to perform basic database operations.