- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MongoDB query to remove entire data from a collection
To remove, use remove() in MongoDB. Let us create a collection with documents −
> db.demo309.insertOne({ "details":[ { "Name":"Chris" }, { "Name":"David" }, { "Name":"Adam" } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5e4eb71af8647eb59e562040") } > db.demo309.insertOne({ "details":[ { "Name":"David" }, { "Name":"Mike" }, { "Name":"Bob" } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5e4eb7cbf8647eb59e562041") }
Display all documents from a collection with the help of find() method −
> db.demo309.find();
This will produce the following output −
{ "_id" : ObjectId("5e4eb71af8647eb59e562040"), "details" : [ { "Name" : "Chris" }, { "Name" : "David" }, { "Name" : "Adam" } ] } { "_id" : ObjectId("5e4eb7cbf8647eb59e562041"), "details" : [ { "Name" : "David" }, { "Name" : "Mike" }, { "Name" : "Bob" } ] }
Following is the query to remove data from big collection −
> db.demo309.remove({});
This will produce the following output −
WriteResult({ "nRemoved" : 2 })
- Related Articles
- MongoDB query to remove entire array from collection?
- How to remove duplicates from MongoDB Collection?
- Retrieve data from a MongoDB collection?
- MongoDB query to pull array element from a collection?
- MongoDB query to update a specific document from a collection
- MongoDB query to rename a collection?
- MongoDB query to remove item from array?
- MongoDB query to remove subdocument from document?
- MongoDB query to find a specific city record from a collection
- MongoDB query to remove array elements from a document?
- MongoDB: How to query a collection named “version”?
- MongoDB query to retrieve records from a collection named with letters and numbers
- How to remove all documents from a collection except a single document in MongoDB?
- MongoDB query to remove a specific document
- Query MongoDB collection starting with _?

Advertisements