CRUD operations
CRUD stands for Create, Read, Update, and Delete—these are the basic operations that you can perform on data stored in a MongoDB database. Below is an overview of how CRUD operations are implemented in MongoDB:
Create
To insert data into a MongoDB collection, you can use methods like insertOne() and insertMany().
Read
Reading or querying data in MongoDB can be done using methods like find() and findOne().
Update
Updating documents in a MongoDB collection can be done using methods like updateOne(), updateMany(), and replaceOne().
Delete
Deleting documents can be done using methods like deleteOne() and deleteMany().
Advanced options
-
MongoDB also supports more advanced CRUD operations, including bulk writes and transactions.
-
You can also use various query operators (
$gt,$lt,$in, etc.) and update operators ($set,$unset,$push, etc.) to perform more complex queries and updates.