Node.js Tutorial
- Node.js Tutorial
- Install Node.js on Windows
- Install Node.js on Linux/Ubuntu/CentOS
- Node.js First Example
- Node.js Console
- Node.js REPL
- Node.js Package Manager
- Node.js Command Line Options
- Node.js Global Objects
- Node.js OS
- Node.js Timer
- Node.js Errors
- Node.js DNS
- Node.js Net
- Node.js Crypto
- Node.js TLS/SSL
- Node.js Debugger
- Node.js Process
- Node.js Child Process
- Node.js Buffers
- Node.js Streams
- Node.js File System (FS)
- Node.js Path
- Node.js StringDecoder
- Node.js Query String
- Node.js ZLIB
- Node.js Assertion Testing
- Node.js V8
- Node.js Callbacks
- Node.js Events
- Node.js Punycode
- Node.js TTY
- Node.js Web Module
- NestJS
Node.js MySQL
Node.js MongoDB
Nodejs Difference
Node.js MCQ
Node.js Express
Nodejs Interview Questions
Node.js MongoDB Create Database
to create a database in MongoDB, First create a MongoClient object and specify a connection URL with the correct ip address and the name of the database which you want to create.
Note: MongoDB will automatically create the database if it does not exist, and make a connection to it.
Example
Create a folder named "MongoDatabase" as a database. Suppose you create it on Desktop. Create a js file named "createdatabase.js" within that folder and having the following code:
- var MongoClient = require('mongodb').MongoClient;
- var url = "mongodb://localhost:27017/MongoDatabase";
- MongoClient.connect(url, function(err, db) {
- if (err) throw err;
- console.log("Database created!");
- db.close();
- });
Now open the command terminal and set the path where MongoDatabase exists. Now execute the following command:
- Node createdatabase.js