linkedin-node-databases icon indicating copy to clipboard operation
linkedin-node-databases copied to clipboard

TypeError: client.isConnected is not a function

Open daviskantor opened this issue 3 years ago • 2 comments
trafficstars

I get the folllowing error when I run the code in VS Studio and try to connect to MongoDB.

TypeError: client.isConnected is not a function at MongoBackend.max (/Users/.../node-databases/maxcoin/services/backend/MongoBackend.js:40:14)

Do you have a suggestion for how I can make this code work? It seems that client.isConnected has been discontinued.

daviskantor avatar Mar 23 '22 16:03 daviskantor

A quick solution is to use "mongodb": "^3.6.2" inside package.json

LeanoA avatar May 12 '22 20:05 LeanoA

So it looks like isConnected is deprecated. All I needed to do is transform it into a try catch, with the catch being if it didn't successfully connect. The other thing that you don't need at that point is the const client because it only gets used for the isConnected function, so you can just do an await like you do with the disconnect at that point.

howardwu1 avatar Sep 11 '22 23:09 howardwu1