
- 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
Remove only a single document in MongoDB
To remove only a single document in MongoDB, use remove(). Let us create a collection with documents −
> db.demo165.insertOne({"ClientId":101,"ClientName":"Chris","ClientAge":34}); { "acknowledged" : true, "insertedId" : ObjectId("5e36895c9e4f06af551997cc") } > db.demo165.insertOne({"ClientId":102,"ClientName":"Bob","ClientAge":32}); { "acknowledged" : true, "insertedId" : ObjectId("5e3689659e4f06af551997cd") } > db.demo165.insertOne({"ClientId":103,"ClientName":"David","ClientAge":35}); { "acknowledged" : true, "insertedId" : ObjectId("5e36896d9e4f06af551997ce") }
Display all documents from a collection with the help of find() method −
> db.demo165.find();
This will produce the following output −
{ "_id" : ObjectId("5e36895c9e4f06af551997cc"), "ClientId" : 101, "ClientName" : "Chris", "ClientAge" : 34 } { "_id" : ObjectId("5e3689659e4f06af551997cd"), "ClientId" : 102, "ClientName" : "Bob", "ClientAge" : 32 } { "_id" : ObjectId("5e36896d9e4f06af551997ce"), "ClientId" : 103, "ClientName" : "David", "ClientAge" : 35 }
Following is the query to remove document from MongoDB −
> db.demo165.remove({"ClientId":102}); WriteResult({ "nRemoved" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo165.find();
This will produce the following output −
{ "_id" : ObjectId("5e36895c9e4f06af551997cc"), "ClientId" : 101, "ClientName" : "Chris", "ClientAge" : 34 } { "_id" : ObjectId("5e36896d9e4f06af551997ce"), "ClientId" : 103, "ClientName" : "David", "ClientAge" : 35 }
- Related Articles
- Update only a single document in MongoDB
- Remove only one document in MongoDB?
- Increment only a single value in MongoDB document?
- Retrieve only a single document specifying a criteria in MongoDB?
- Update only a single MongoDB document without deleting any date
- How to find only a single document satisfying the criteria in MongoDB?
- How to remove all documents from a collection except a single document in MongoDB?
- Remove all except a single field from a nested document via projection in MongoDB
- MongoDB findById returning a list of documents instead of a single result? How to get only a single document?
- MongoDB findOneAndUpdate() to update a single document
- MongoDB query to remove a specific document
- Decrement only a single value in MongoDB?
- Update only a specific value in a MongoDB document
- Update a single list item of a MongoDB document?
- Remove values from a matrix like document in MongoDB

Advertisements