![]() |
VOOZH | about |
mongodb.connect() method is the method of the MongoDB module of the Node.js which is used to connect the database with our Node.js Application. This is an asynchronous method of the MongoDB module.
Syntax:
mongodb.connect(path,callbackfunction)
Parameters: This method accept two parameters as mentioned above and described below:
Connecting MongoDB to Node.js is essential for managing data in full-stack applications.
Installing module:
npm install mongodb --save
Project structure:
👁 ImageCommand to run server on particular ip:
mongod --dbpath=data --bind_ip 127.0.0.1👁 Image
FileName index.js
Running command:
node index.js
Output:
node index.js
(node:7016) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(Use `node --trace-deprecation ...` to show where the warning was created)
successful connection with the server