MongoDB - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

MongoDB Database

MongoDB Database

Creating Database

shape Description

MongoDB Database can be created by using creating DATABASE_NAME. Then a new database will be created, if the new database doesn't exist then it moves to the database that is existing. MongoDB doesn't contribute a commands for creating a new database. Indeed it doesn't need for creating it physically. Since MongoDB will make it on the fly, amid the first occasion when sparing the quality into the characterized accumulation. MongoDB consists of "db.createCollection()"for creating complications physically, yet Not database.

shape Syntax

The syntax for creating a new MongoDB Database is as follows: 
use DATABASE_NAME

shape Examples

The below example describes how to create a new MongoDB Database. [c]MongoDB shell version: 3.2.7 connecting to: test > show dbs local 0.000GB > use admin switched to db admin > show collections > use company switched to db company > db company >[/c] Here in the above example a company database name has been successfully created.

Drop database

shape Description

The drop database command is utilized for dropping a MongoDB Database which is already existing.

shape Syntax

The syntax for dropping an existing database is as follows: 
dp.dropDatabase()

shape Examples

The below example describes how to drop an existing database. [c] MongoDB shell version: 3.2.7 connecting to: test >show dbs local 0.000GB mydb 0.000GB >use mydb switched to db mydb >db.mycollection.insert({"name":"max"}) >db.dropDatabase >{ "dropped" : "mydb", "ok" : 1 } > [/c] Here in the above example a the database name mydb  has been successfully dropped.

Summary

shape Key Points

  • MongoDB Database - Creating DATABASE_NAME is used to create a new database.
  • MongoDB Drop database - Is used to drop an existing database.