DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Short Note on CRUD Operations of MongoDB…
Tonmoy Roy
Tonmoy Roy

Posted on • Updated on

Short Note on CRUD Operations of MongoDB…

MongoDB CRUD Operations

CRUD operations create, read, update, and delete documents in MongoDB.

Create Operations
Create or insert operations add new documents to a collection in the database. If the collection does not currently exist in the database, then insert operations will create the collection.

MongoDB provides the following methods to insert documents into a collection:

  • db.collection.insertOne()
  • db.collection.insertMany() Here, insert operations target a single collection.

Read Operations
Read operations retrieve documents from a collection in the database.

MongoDB provides the following methods to read documents from a collection:

  • db.collection.find() We can specify query filters or any criteria that identify the documents to return.

Update Operations
Update operations modify existing documents in a collection of the database.

MongoDB provides the following methods to update documents of a collection:

  • db.collection.updateOne()
  • db.collection.updateMany()
  • db.collection.replaceOne() Here, update operations target a single collection. We can also specify any criteria, or filters, that identify the documents to update.

Delete Operations
Delete operations remove documents from a collection in the database.

MongoDB provides the following methods to delete documents of a collection:

  • db.collection.deleteOne()
  • db.collection.deleteMany() Here, delete operations target a single collection. We can specify any criteria, or filters, that identify the documents to remove.

Top comments (0)

12 Gorgeous UI Components for Your Design Inspiration

>> Check out this classic DEV post <<