
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- MongoDB query to remove entire array from collection?
- Retrieve data from a MongoDB collection?
- How to remove duplicates from 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 remove array elements from a document?
- MongoDB query to find a specific city record from a collection
- Query MongoDB collection starting with _?
- How do I query a MongoDB collection?
- MongoDB query to remove a specific document
- Delete data from a collection in MongoDB using multiple conditions?
- Can we remove _id from MongoDB query result?
Advertisements