9951 explained code solutions for 126 technologies


mongodbHow to create a database in MongoDB?


Creating a database in MongoDB is a simple process.

use <database_name>

This command will create a new database if it does not already exist, or connect to an existing database if it does exist.

  1. use <database_name>: This command creates a new database if it does not already exist, or connects to an existing database if it does exist.
  2. db.createCollection(<collection_name>): This command creates a new collection in the current database.
  3. db.collection.insert(<document>): This command inserts a document into the specified collection.

Helpful links

Edit this code on GitHub