
- 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
How to delete a table from MongoDB database?
Use drop() to delete a table. Following is the syntax −
db.yourCollectionName.drop();
Let us first create a collection with documents −
> db.deleteTableDemo.insertOne({"Name":"Chris","Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb705140b992277dae0e6") } > db.deleteTableDemo.insertOne({"Name":"Carol","Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb70c140b992277dae0e7") } > db.deleteTableDemo.insertOne({"Name":"David","Age":24}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb714140b992277dae0e8") }
Following is the query to display all documents from a collection with the help of find() method −
> db.deleteTableDemo.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5ccfb705140b992277dae0e6"), "Name" : "Chris", "Age" : 23 } { "_id" : ObjectId("5ccfb70c140b992277dae0e7"), "Name" : "Carol", "Age" : 21 } { "_id" : ObjectId("5ccfb714140b992277dae0e8"), "Name" : "David", "Age" : 24 }
Here is the query to delete a table from MongoDB database −
> db.deleteTableDemo.drop();
This will produce the following output −
True
Above, True is returned i.e. the table deleted successfully.
- Related Questions & Answers
- How to delete everything in a MongoDB database?
- How can you delete a table from a database in MySQL Python?
- How to delete a column from an existing table in a database using JDBC API?
- How to delete documents from a collection in MongoDB?
- How to delete a row from a table using jQuery?
- How to delete a column from a table in MySQL?
- How to use Boto3 to delete a database from AWS Data Catalog?
- Delete multiple entries from a MySQL table
- How to retrieve table names from a database in MySQL?
- How to list all collections from a particular MongoDB database?
- How to drop a table from a database using JDBC API?
- How to copy a table from one MySQL database to another?
- How to normalize a Database Table
- How to delete all the documents from a collection in MongoDB?
- How can we delete a MySQL stored function from the database?
Advertisements