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

Mongodb

Mongodb Problem Overview


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

(I failed to find it on Google)

Mongodb Solutions


Solution 1 - Mongodb

Found it by guessing :) Simply:

db

Solution 2 - Mongodb

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.

Solution 3 - Mongodb

db.current

is a CLI command that will show you the database you are currently working in

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHaoQi LiView Question on Stackoverflow
Solution 1 - MongodbHaoQi LiView Answer on Stackoverflow
Solution 2 - MongodbAsya KamskyView Answer on Stackoverflow
Solution 3 - Mongodbkat3ngView Answer on Stackoverflow