'mongo.isConnected alternative for node driver v4+
Is there any alternative for the deprecated MongoClient.isConnected in the native Node JS MongoDB driver?
I read somewhere that one can handle the check via callbacks, which one can pass as parameters in the .connect Method (See the docs.) However, I wasn't able to successfully do that.
Solution 1:[1]
You can connect to MongoDB with the mongoose.connect() method.
mongoose.connect('mongodb://localhost:27017/myapp');
Install Mongoose from the command line using npm:
$ npm install mongoose --save
Refer to my MongoDB + Node example:
https://github.com/juhisri211/node-mongo-app/blob/master/index.js
For more details about Mongoose, please refer to official documentation:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Juhi S |
