What is the command to show the current db in the MongoDB shell?
(I failed to find it on Google)
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.
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.
Found it by guessing :) Simply:
db
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.
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