Nodejs MongoDB Create Database

Node.js MongoDB Create Database

In order to create a MongoDB database , we have to first create a MongoClient object, then to pass a connection URL with the correct ip address and the name of the database you would like to create. MongoDB engine first check for the database if it does not exist then it creates and make a connection to the database.

Example :- Let’s create MongoDB database named as “nodemongo”

Step 1:-  Let’s, create a node_mongo_create_db.js file and put the following code in it –

Step 2:- Save the code and open the terminal again, and type the following command in order to run the file.

you will see following output on terminal –

Output:-