Mongo/Databases
From charlesreid1
Getting Info About Databases
Mongo shell
Start the mongo shell:
$ mongo >
To list all available databases, use any of these commands:
> db.adminCommand('listDatabases')
> db.getMongo().getDBNames()
> show databases
> show dbs
Show all tables and collections in a database:
> use test_db > show tables > show collections > db.getCollectionNames()
Command line
To bypass the javascript shell and run commands directly from the command line, run the commands using --eval:
mongo <dbname> --eval "db.getMongo().getDBNames()" mongo <dbname> --eval "db.getCollectionNames()" mongo <dbname> --eval "db.dropDatabase()"
Removing (Dropping) Databases
To remove (drop) a database, use the db.dropDatabase() function. From the mongo shell:
$ mongo > use test_db > db.dropDatabase()