This demo will show you how to create database mongoDB . Please follow below steps:

  • Install and start mongoDB using this tutorial URL: Install mongoDB 
  • Now go to mongoDB bin folder look for what are default database available. It shows only one default database name local:

mongoDB2

  • To create new database execute below command: use mongoTestDB (Note : database will not be created until you save some document in it.

mongoDB3

 

  • Confirm that your session has the mongoTestDB database as context, by checking the value of the db object, which returns the name of the current database, as follows:

mongoDB4

 

  • Until now, if you issue the show dbs operation again, it will not include the mongoTestDB database. mongoTestDB will not permanently create a database until you insert data into that database.
  • Now insert document to create a database permanently
  • . Use following command to insert data:

mongoDB5

  • This will create database name mongoTestDB permanently.

Leave a Reply

Your email address will not be published. Required fields are marked *