In MongoDB, the first basic step is to have a database and collection in place. The database is used to store all of the collections, and the collection in turn is used to store all of the documents.

The documents in turn will contain the relevant Field Name and Field values. For more info MongoDB Online Training
MongoDB didn’t provides any command to create “database“. Actually, you don’t need to create it manually, because, MangoDB will create it on the fly, during the first time you save the value into the defined collection (or table in SQL), and database.
For developer from SQL background, we need to create a database, table and insert values into table manually. In MongoDB, you don’t need to mention what you want to create, when first time you save the value into the defined collection (table), under selected database, MangoDB will create the value, collection and database automatically.
Define a database name:
Issue “use new-databasename” to switch from default database to define database (even non-exists database name will work). However, MangoDB doesn’t create any database yet, until you save something inside.
> use abcd
switched to db abcddb
> show dbs
admin 0.04125GB
local (empty)
MongoShell:
The mongo shell is an interactive JavaScript interface to query and update data as well as perform administrative operations in MongoDB.
Databases: In MongoDB, databases basically holds the collections of documents. A database contains collection which contains the document. On a single MongoDB server, we can run multiple databases. Default created database of MongoDB is ‘db’ present within the data folder. When you install MongoDB some databases are automatically generated to use.so we can say that it is not required to create a database before you start working with it. Learn more programming skills from MongoDB Training
Create a New Database : You can create a new Database in MongoDB by using “use Database_Name” command. The command creates a new database if it doesn’t exist, otherwise, it will return the existing database.you can run this command in mongo shell to create a new database. Your newly created database is not present in the list of Database. To display database, you need to insert at least one document into it.
Syntax:
use Database_Name
Following is the explanation for each mongodb command we executed above
- show dbs there are two databases already, admin and local.
- use tutorialkart switched to tutorialkart database.
- show dbs but tutorialkart is not actually created yet.
- db.users.insertOne() makes a check if the database is present. If database is not present, it creates one with the name of database that has been switched to (in step 2) and inserts the Document into the database.
- show dbs now there are three databases, including our newly created tutorialkart database.
Example:
{
create: <collection or view name>,
capped: <true|false>,
autoIndexId: <true|false>,
size: <max_size>,
max: <max_documents>,
storageEngine: <document>,
validator: <document>,
validationLevel: <string>,
validationAction: <string>,
indexOptionDefaults: <document>,
viewOn: <source>, // Added in MongoDB 3.4
pipeline: <pipeline>, // Added in MongoDB 3.4
collation: <document>, // Added in MongoDB 3.4
writeConcern: <document>
}
To get in-depth knowledge, enroll for a live free demo on MongoDB Certification