
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
Command to show the database currently being used in MongoDB?
The command to show the database currently used in MongoDB is the following −
db;
Let us first check how many databases are present. The query is as follows −
> show dbs;
The following is the output displaying all the databases −
admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB studentSearch 0.000GB test 0.003GB
Now, we have the list of all databases. Let us use the above syntax to check current database. The query is as follows −
> db;
The following is the output −
sample
Look at the above sample output, we are currently using ‘sample’ database. Let us switch the database and verify again the correctness of command db.
The query is as follows to switch database.
> use test;
The following is the output −
switched to db test
Look at the above sample output, we have changed the database from ‘sample’ to ‘test’.
Now let us once again check the current database name. The query is as follows −
> db;
The following is the output −
test
Use the function getName(). The query is as follows −
> db.getName();
The following is the output −
test
You can use the current command to check the current working database −
The query is as follows −
> db.current;
The following is the output −
test.current
- Related Articles
- Does MongoDB getUsers() and SHOW command fulfil the same purpose?
- How do I drop a MongoDB database from the command line?
- Drop all indexes from all the collections in a MongoDB database using the command line?
- MongoDB query to update field and modify the data currently in column
- Connecting to MySQL database from the command line?
- What is the BSON query for the command 'show dbs' (list of databases) in MongoDB?
- Connect to MySQL database from command line
- How should I display MySQL database that is currently in use?
- How to stop MongoDB in a single command?
- How to create a database on command line in MySQL?
- Show constraints on table command in MySQL?
- Combine SELECT & SHOW command results in MySQL?
- How to start a DB2 database DSNDB001 using the command panel?
- What is the panel command to display all DB2 database components?
- How to drop a database in MongoDB?
