DEV Community

Barshon
Barshon

Posted on

CRUD

CRUD, the word is denoting four core operations when it comes to data management in databases. The C stands for create, the R stands for read, the U stands for update and the D stands for delete. So, CRUD operations are fundamental operations of database data management involving create,read,update and delete.

For instance, if we talk about MongoDB, like any other database, the MongoDB also requires and supports all the crud operations. I'll explain briefly on every crud operations in the MongoDB.

First, the create operation. The create operation (also called the insert operation) is the operation in MongoDB where we create a document and add it to a certain collection in the database. This is the first and foremost operation in the crud.

db.collection.insertOne() 
db.collection.insertMany()
Enter fullscreen mode Exit fullscreen mode

Then comes the read operation. The read operation in a database is based on the idea that when an user query is launched, certain data should be able to be accessed (read) and show accordingly. For this purpose, the read operation is needed in the database.

db.collection.find()
Enter fullscreen mode Exit fullscreen mode

In the third scenario, comes the update operation. Often it needs to update the data according to new circumstance and situations. For this case, databases need to support the update operation. MongoDB also supports the update operation.

db.collection.updateOne() 
db.collection.updateMany() 
db.collection.replaceOne()
Enter fullscreen mode Exit fullscreen mode

Last comes the final of the four operations, the delete operation. It just so happens that delete is a very core operation when it comes to database because often it might be needed to delete the existing data in the database.

db.collection.deleteOne() 
db.collection.deleteMany() 
Enter fullscreen mode Exit fullscreen mode

So, that covers up all the crud operations in a database. This is based on MongoDB but crud is supported by every databases out there.

Top comments (0)