Create Database

firstly open the terminal. If you have mongo credentials then write the below command.


mongo -u admin
Enter password:

Note:- where admin is a username

If you did not create credentials then you can directly login write the command


mongo

Now, create the database through below command
use DatabaseName


 > use employee_management
 > switched to db employee_management

if you want to see all databases then write the below command.


> show dbs

Note:- it will show all databases which has collection.

Create Database – Interview Questions

Q 1: How do you create a database in MongoDB?
Ans: Use the databaseName command. The database is created when data is inserted.
Q 2: How do you check the current database?
Ans: Use db command.
Q 3: How do you list all databases?
Ans: Use show dbs.
Q 4: Does MongoDB create empty databases?
Ans: No, MongoDB creates the database only after inserting data.
Q 5: How do you switch databases?
Ans: Use use databaseName.

Related Create Database Topics