Switch to Other Database

To switch to other database use the command ” use Database_Name” command. If Database does not exists then it will create a new Database.

Switch to other Database Example

The below image shows how to switch to another database using Mongo Shell.

In the above Example, First we check current Database name using db command which was UserDB then we use “use test” command to switch to database test.

References: https://docs.mongodb.com/manual/core/databases-and-collections/#databases

MongoDB – Create Database using Mongo Shell

A MongoDB Database is the container for all the collections, where the Collection is a bunch of MongoDB documents similar to tables in RDBMS and the Document is made up of fields similar to a tuple in RDBMS, but it has a dynamic schema here.

This article explains the easy method to create a Database in MongoDB using Mongo Shell.

Similar Reads

How to Create a MongoDB Database Using Mongo Shell

To create a new MongoDB database using Mongo Shell use the “use Database_Name” command. This command creates a new database if it doesn’t exist, otherwise, it will return the existing database....

Show list of Databases

To check currently selected database, use the command “show dbs“....

Check Current Database

To check the current database use the “db” command....

Switch to Other Database

To switch to other database use the command ” use Database_Name” command. If Database does not exists then it will create a new Database....

Conclusion

This guide explained easy way to create a database using Mongo Shell. We also covered different database related operations using Mongo Shell. We discussed commands to view database list, check current database and switch to another database....

Contact Us