Quantcast
Channel: SQL Server Blog
Viewing all articles
Browse latest Browse all 1849

MongoDB – Drop database

$
0
0

The dropDatabase command drops the current database, deleting the associated data files.

Different methods to drop database

Method 1:

1. select the database which you want to delete
>use < database name >
2. Then issue the below command
>db.dropDatabase()

Method 2:

1. Define the name of the database
> var dbname=”users”
2. Issue the below command
> Mongo().getDB(dbname).dropDatabase()
{ “dropped” : “users”, “ok” : 1 }

DropDatabase-2

Dropping all the databases

*****Please make a copy before deleting anything****

The first command gives you a list of dbs ‘AA’ and ‘PP’ and the second one using cursor loop through all the database and drop the databases

>db.getMongo().getDBs()[“databases”].forEach(function(dbname){ var db1=db.getMongo().getDB(dbname.name); print (db1);});
AA
PP
> db.getMongo().getDBs()[“databases”].forEach(function(dbname){ db.getMongo().getDB(dbname.name).dropDatabase();});
> show dbs

DropDatabase-1



Viewing all articles
Browse latest Browse all 1849

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>