You can also use the db command to see your current database.
Use the db. getCollectionNames() Method to List All Collections in the MongoDB Shell. The function db. getCollectionNames() returns an array with the names of all collections and views in the current database.
You can create new connections within the mongo shell. Open a new database connection. Open a connection to a new server using new Mongo() . Use getDB() method of the connection to select a database.
Listing all the databases in mongoDB console is using the command show dbs
.
For more information on this, refer the Mongo Shell Command Helpers that can be used in the mongo shell.
For database list:
show databases
show dbs
For table/collection list:
show collections
show tables
db.getCollectionNames()
For MongoDB shell version 3.0.5 insert the following command in the shell:
db.adminCommand('listDatabases')
or alternatively:
db.getMongo().getDBNames()
From the command line issue
mongo --quiet --eval "printjson(db.adminCommand('listDatabases'))"
which gives output
{
"databases" : [
{
"name" : "admin",
"sizeOnDisk" : 978944,
"empty" : false
},
{
"name" : "local",
"sizeOnDisk" : 77824,
"empty" : false
},
{
"name" : "meteor",
"sizeOnDisk" : 778240,
"empty" : false
}
],
"totalSize" : 1835008,
"ok" : 1
}
To list mongodb database on shell
show databases //Print a list of all available databases.
show dbs // Print a list of all databases on the server.
Few more basic commands
use <db> // Switch current database to <db>. The mongo shell variable db is set to the current database.
show collections //Print a list of all collections for current database.
show users //Print a list of users for current database.
show roles //Print a list of all roles, both user-defined and built-in, for the current database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With