Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to show the db that I'm currently using in MongoDB?

Tags:

mongodb

What is the command to show the current db in the MongoDB shell?

(I failed to find it on Google)

like image 543
HaoQi Li Avatar asked Apr 14 '13 20:04

HaoQi Li


People also ask

How do I display a database in MongoDB?

In MongoDB, you can use the show dbs command to list all databases on a MongoDB server. This will show you the database name, as well as the size of the database in gigabytes. You can select any database using the use statement and work on it.

Which command can be used to show existing databases in MongoDB is running?

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.


2 Answers

Found it by guessing :) Simply:

db

like image 162
HaoQi Li Avatar answered Sep 28 '22 07:09

HaoQi Li


The command to get database name in the shell is:

> db.getName() 

While just typing db works, you will find that this only works interactively and if you're working on a script this may not give the result you want.

like image 45
Asya Kamsky Avatar answered Sep 28 '22 08:09

Asya Kamsky