Nodejs MongoDB Create Database

In this tutorial you will learn about the Nodejs MongoDB Create Database and its application with practical example.

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.

Table Of Contents

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:-

 

In this tutorial we have learn about the Nodejs MongoDB Create Database and its application with practical example. I hope you will like this tutorial.