
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to delete a document in MongoDB?
To delete a document, use remove(). Let us create a collection with documents −
> db.demo79.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2bdb2271bf0181ecc42293") } > db.demo79.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2bdb2671bf0181ecc42294") } > db.demo79.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2bdb2971bf0181ecc42295") } > db.demo79.insertOne({"Name":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2bdb2c71bf0181ecc42296") }
Display all documents from a collection with the help of find() method −
> db.demo79.find();
This will produce the following output −
{ "_id" : ObjectId("5e2bdb2271bf0181ecc42293"), "Name" : "Chris" } { "_id" : ObjectId("5e2bdb2671bf0181ecc42294"), "Name" : "David" } { "_id" : ObjectId("5e2bdb2971bf0181ecc42295"), "Name" : "Bob" } { "_id" : ObjectId("5e2bdb2c71bf0181ecc42296"), "Name" : "Mike" }
Following is the query to delete a document in MongoDB −
> db.demo79.remove({"Name":"Bob"}); WriteResult({ "nRemoved" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo79.find();
This will produce the following output. We deleted a document successfully −
{ "_id" : ObjectId("5e2bdb2271bf0181ecc42293"), "Name" : "Chris" } { "_id" : ObjectId("5e2bdb2671bf0181ecc42294"), "Name" : "David" } { "_id" : ObjectId("5e2bdb2c71bf0181ecc42296"), "Name" : "Mike" }
- Related Articles
- How to delete a MongoDB document using Java?
- How to delete particular data in a document in MongoDB?
- How to delete document by _id using MongoDB?
- How to delete document from a collection in MongoDB using deleteOne() method?
- How do I delete array value from a document in MongoDB?
- How to add a sub-document to sub-document array in MongoDB?
- How to delete everything in a MongoDB database?
- How to get embedded data in a MongoDB document?
- How to insert a document with date in MongoDB?
- How to replace substring in MongoDB document?
- How to delete documents from a collection in MongoDB?
- How to delete multiple ids in MongoDB?
- How to delete partial data in MongoDB?
- How to count number of keys in a MongoDB document?
- How to delete a table from MongoDB database?

Advertisements