The Wayback Machine - https://web.archive.org/web/20241126180939/https://www.geeksforgeeks.org/mongodb-delete-database-using-mongoshell/
Open In App

MongoDB | Delete Database using MongoShell

Last Updated : 19 Nov, 2019
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisite : MongoDB Introduction

Short Description : A MongoDB Database is a container for all the collections, where Collection is a bunch of MongoDB documents similar to tables in RDBMS and Document is made of fields similar to a tuple in RDBMS, but it has a dynamic schema here.
Example of a Document :

{
        "Name" : "Aman",
        Age : 24,
        Gender : "Male"    
}

Example of a Collection :

[    
    {
        "Name" : "Aman",
        Age : 24,
        Gender : "Male"    
    },
    {
        "Name" : "Suraj",
        Age : 32,
        Gender : "Male"    
    },
    {
        "Name" : "Joyita",
        "Age" : 21,
        "Gender" : "Female"
    }
]

MongoShell : The mongo shell is an interactive JavaScript interface to query and update data as well as perform administrative operations in MongoDB. Detailed explanation about the Mongo shell is given on this site.

Drop a Database : In MongoDB, databases hold collections of documents. On a single MongoDB server, we can run multiple databases. when you install MongoDB some databases are automatically generated to use. many times you need to delete some database when the database is no longer used.

db.dropDatabase() the command is used to drop an existing database. This command will delete the currently selected database. If you have not selected any database, then it will delete the default ‘test’ database.

Syntax :

 db.dropDatabase()

Example : The below screenshot is showing the use of “db.dropDatabase()” command for a newly created database name userDB.

How to delete a database which is not currently used : You can check currently selected database, using the command “db“. Then you can use “show dbs” command for checking the list of Databases. Then select the database you want to delete using command “use databasename“. Then execute db.dropDatabase() command to drop an existing database.

Example : In below example we were using a database name userDB and we want to delete a different database name adminDB. so first we are going to select adminDB database then we will delete this database.

References:
https://docs.mongodb.com/manual/core/databases-and-collections/#databases


Previous Article
Next Article

Similar Reads

Delete Single Document in MongoDB Using MongoShell
deleteOne method is used to delete a single document in MongoDB. This method deletes a single existing document from the collection that matches the specified filter. This method can be used in multi-document transactions. It deletes the first document that matches the condition if multiple documents satisfy the condition. Note: MongoDB deleteOne m
3 min read
MongoDB - Insert Single Document Using MongoShell
In MongoDB, insert operations are used to add new documents in the collection. If the collection does not exist, then the insert operations create the collection by inserting documents. Or if the collection exists, then insert operations and add new documents to the existing collection. You are allowed to add a single document in the collection usi
2 min read
MongoDB - Insert Multiple Document Using MongoShell
In MongoDB, insert operations are used to add new documents in the collection. If the collection does not exist, then the insert operations create the collection by inserting documents. Or if the collection exists, then insert operations add new documents in the existing collection. You are allowed to insert multiple documents in the collection by
2 min read
MongoDB - Update Single Document Using MongoShell
In MongoDB, you can update a single document in the collection using db.collection.updateOne() method. This method updates a document in the collection according to the filter. updateOne() is a mongo shell method, which can updates one document at a time. This method update the first document that satisfies the given condition in the collection. Or
4 min read
MongoDB - Update Multiple Documents Using MongoShell
In MongoDB, you can update multiple documents in the collection using db.collection.updateMany() method. This method updates all the documents in the collection that match the given filter. updateMany() is a mongo shell method, which can update multiple document. This method only accepts the documents that contain update operator expressions. updat
3 min read
MongoDB - Replace Documents Using MongoShell
In MongoDB, you are allowed to replace an existing document with a new document in the collection with the help of db.collection.replaceOne() method. This method will replace the existing document with the replacement document. replaceOne() is a mongo shell method, which only replaces one document at a time. The replacement document may contain dif
4 min read
MongoDB - Delete Multiple Documents Using MongoDB Shell
The db.collection.deleteMany() method is used to delete multiple documents from a collection in Mongo Shell. This method deletes multiple documents from the collection according to the filter. The deleteMany() is a Mongo shell method, which can delete multiple documents. This method can be used in multi-document transactions. If you use this method
2 min read
Connect MongoDB (AWS) from Local Machine using WinSCP and MongoDB Compass
Pre-requisite: AWS and MongoDB In this article, we are going to connect to the Mongo database of the AWS Ubuntu Server instance using WinSCP and learn how to get connected to the server from your local machine using MongoDB Compass.  If you haven't installed a MongoDB server in your AWS EC2 instance then follow the steps present in this article and
4 min read
How to delete single and multiple documents in MongoDB using node.js ?
MongoDB, the most popular NoSQL database is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data. This format of storage is called BSON (similar to JSON for
2 min read
How to Delete a Document From MongoDB Collection using NodeJS?
MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. This means that MongoDB isn’t based on a table-like relational database structure but provides an altogether different mechanism for data storage and retrieval. This storage format is called BSON ( similar to JSON format)
4 min read
How to find all the values of particular key of MongoDB Database using Node.js ?
MongoDB module: This module of Node.js is used for connecting the MongoDB database as well as used for manipulating the collections and databases in MongoDB. The mongodb.connect() is the main method that is used for connecting to the MongoDB database which is running on a particular server on your machine (Refer to this article). We can also use pr
2 min read
How to create new Mongodb database using Node.js ?
mongodb module: This Module is used to performing CRUD(Create Read Update Read) Operations in MongoDb using Node.js. We cannot make a database only. We have to make a new Collection to see the database. The connect() method is used for connecting the MongoDb server with the Node.js project. Please refer this link for connect() method. Installing mo
1 min read
How to drop database of MongoDB using Node.js ?
MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data. This format of storage is called BSON ( similar to JSON f
2 min read
How to get information of all collections present in MongoDB database using Node.js ?
MongoDB, the most popular NoSQL database, we can count the number of documents in MongoDB Collection using the MongoDB collection.countDocuments() function. The mongodb module is used for connecting the MongoDB database as well as used for manipulating the collections and databases in MongoDB. Installing module: You can install mongodb module using
1 min read
How to sort collection of MongoDB Database in ascending order using Node.js ?
MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data. This format of storage is called BSON ( similar to JSON f
2 min read
How to sort collection of MongoDB Database in descending order using Node.js ?
MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data. This format of storage is called BSON ( similar to JSON f
2 min read
MongoDB - Create Database using Mongo Shell
A MongoDB Database is the container for all the collections, where the Collection is a bunch of MongoDB documents similar to tables in RDBMS and the Document is made up of fields similar to a tuple in RDBMS, but it has a dynamic schema here. This article explains the easy method to create a Database in MongoDB using Mongo Shell. How to Create a Mon
2 min read
How to Connect to a MongoDB Database Using the Node.js Driver ?
MongoDB is a popular, open-source, NoSQL (non-relational) database that provides high performance, high availability, and easy scalability. Unlike traditional relational databases, MongoDB stores a JSON-like format called BSON (Binary JSON). In this article, we connect the MongoDB database to your backend application built by Node.js. Setup for Dat
4 min read
How to Connect to a MongoDB Database Using Node.js
MongoDB is a NoSQL database used to store large amounts of data without any traditional relational database table. To connect to a MongoDB database using NodeJS we use the MongoDB library "mongoose". Steps to Connect to a MongoDB Database Using NodeJSStep 1: Create a NodeJS App: First create a NodeJS app using the following command: npm init -ycd f
4 min read
Create Database using MongoDB Compass
MongoDB uses a document-oriented storage model which contrasts with traditional relational databases. Instead of storing data in tables with rows and columns, MongoDB stores data as documents in BSON format. In this article, We will learn about How to Create a Database using MongoDB Compass in detail. Understanding MongoDB Document-Oriented Storage
5 min read
MongoDB Shell vs MongoDB Node.JS Driver
MongoDB Shell and the MongoDB Node.js Driver are both tools for interacting with MongoDB, but they serve different purposes and are used in different contexts. Here's a comparison of the two: MongoDB Node.JS DriverA Node.js package called the MongoDB Node.js Driver enables programmatic communication between applications and MongoDB databases. Throu
4 min read
MongoDB Compass vs MongoDB Atlas
MongoDB is a popular NoSQL database known for flexibility and scalability. MongoDB Compass offers a graphical interface for managing databases visually while MongoDB Atlas is a cloud-based service for automated management and scaling of MongoDB databases. In this article, We will learn about the in-depth understanding of the difference between the
5 min read
How to Back Up and Restore a MongoDB Database?
MongoDB is considered one of the classic examples of NoSQL systems. Its documents are made up of key-value pairs, which are the basic unit of data in MongoDB. Its collections contain groups of documents and functions that are equivalent to tables in relational databases. MongoDB is a database that emerged in the mid-2000s. In this article, we will
4 min read
Sending Data from a Flask app to MongoDB Database
This article covers how we can configure a MongoDB database with a Flask app and store some data in the database after configuring it. Before directly moving to the configuration phase here is a short overview of all tools and software we will use. MongoDB is an open-source database that stores data in JSON-like documents. It is classified as a NoS
5 min read
Multiple MongoDB database Connections in NodeJS
In this guide, we will walk through the process of setting up a Node.js application that connects to multiple MongoDB databases using Mongoose. This is useful in scenarios where you need to manage different datasets separately, such as handling user data in one database and order data in another. Project OverviewThe application we will build is a s
5 min read
How to Connect Node to a MongoDB Database ?
To connect node to a MongoDB database we can use mongoose library from npm, It is an Object Data Modeling Library that provides predefined methods for database connection, creating schema and models. MongoDB is a NoSQL database used to store large amounts of data without any traditional relational database table. Instead of rows & columns, Mong
3 min read
How to Create Database and Collection in MongoDB
MongoDB is a widely used NoSQL database which is used for its flexibility and scalability in managing data. Creating a database in MongoDB is a simple process using the use command. In this article, we'll explore how to create a database, create collections, and insert documents into collections in MongoDB. Creating a Database and Collection in Mon
3 min read
How To Connect MongoDB Database in a Node.js Applications ?
To connect MongoDB to a Node.js application, you can follow a simple process using the Mongoose library, which provides a flexible way to work with MongoDB. Mongoose acts as an Object Data Modeling (ODM) library, making it easier to structure and interact with MongoDB from Node.js. Prerequisites:Node jsMongoDBApproachTo connect MongoDB to the Node
2 min read
MongoDB - Database, Collection, and Document
Databases, collections, documents are important parts of MongoDB without them you are not able to store data on the MongoDB server. A Database contains one or more collections, and a collection contains documents and the documents contain data, they are related to each other. DatabaseIn MongoDB, a database contains the collections of documents. One
6 min read
Which one method use to delete an element from JavaScript array (slice or delete) ?
We can use both methods to delete an element from a javascript array. The answer is solely dependent on the application and on the programmer. What slice() method does? The slice method, as the name suggests, slices an array and returns a copy of the new array. This method does not affect the main array, it just returns the copy of the array. We ca
4 min read
Article Tags :
three90RightbarBannerImg