Wednesday, January 6, 2016

How to create and drop Mongo Database?

Here we will learn to create and drop the MongoDB database. For this we have to require MongoDB client and server.(How to setup MongoDB?).

Step-1: Run MongoDB server

Open the command prompt window. Then run mongod command for run the MongoDB server.


Step-2: Run MongoDB client

Open another command prompt window. Then run mongo command to run the MongoDB client. All the query will be executed in client window.

Create the Database

In client window type follow command to create or change the current database.
Here use command used to change the database that is available if that named database is not available than it will create new database automatically.  use command will not give any type of error.



Drop the Database

In client window type follow command to drop the current database.



Here dropDatabase() function is used to drop the database with current database reference variable db.

Note: Before drop any database its good to make it as current database with use command.

1 comment: