
- 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
MongoDB query to remove a specific document
To remove a specific document, use remove() in MongoDB. Let us create a collection with documents −
> db.demo56.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e272e0bcfb11e5c34d89917") } > db.demo56.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e272e10cfb11e5c34d89918") } > db.demo56.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e272e13cfb11e5c34d89919") }
Display all documents from a collection with the help of find() method −
> db.demo56.find();
This will produce the following output −
{ "_id" : ObjectId("5e272e0bcfb11e5c34d89917"), "Name" : "Chris" } { "_id" : ObjectId("5e272e10cfb11e5c34d89918"), "Name" : "David" } { "_id" : ObjectId("5e272e13cfb11e5c34d89919"), "Name" : "Bob" }
Following is the query to remove a specific document −
> db.demo56.remove({_id:ObjectId("5e272e10cfb11e5c34d89918")}); WriteResult({ "nRemoved" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo56.find();
This will produce the following output −
{ "_id" : ObjectId("5e272e0bcfb11e5c34d89917"), "Name" : "Chris" } { "_id" : ObjectId("5e272e13cfb11e5c34d89919"), "Name" : "Bob" }
- Related Articles
- MongoDB query to remove subdocument from document?
- MongoDB query to remove array elements from a document?
- MongoDB query to update a specific document from a collection
- MongoDB query to pull a specific value from a document
- MongoDB query to implement nor query to fetch documents except a specific document
- MongoDB query select and display only a specific field from the document?
- MongoDB query to fetch a specific document rom documents with field value set using NumberInt()?
- MongoDB query to update nested document
- Return specific MongoDB embedded document
- Filter specific values from a MongoDB document
- Extract a MongoDB document with a specific string
- Remove only a single document in MongoDB
- MongoDB query to return only embedded document?
- MongoDB query to get last inserted document?
- MongoDB query to update the nested document?

Advertisements