MongoDB Create Database - MongoDB

How to create database in MongoDB?

In this chapter, we will explain how to create a database in MongoDB.

Use Command

MongoDB use DATABASE_NAME is used for creating a database. This command will create a new database if it doesn't exist, else it will return the existing database.

Syntax

Basic syntax of use DATABASE statement is as follows

Example

For creating a database with name <mydb>, then use DATABASE statement would be as follows

To check current database, use the command db

To check the databases list, use the command show dbs.

Created database (mydb) will not be present in list. To display the database, at least one document should be inserted into it.

Default database in MongoDB is test. If you are not creating any database, then collections will be stored in test database.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MongoDB Topics