how to check the client is available?

7 views
Skip to first unread message

古格沙

unread,
May 30, 2018, 2:58:52 AM5/30/18
to node-mongodb-native
my first plan is like bellow.

mongodb.MongoClient.connect( uri, function( err, client )
{
     let db
= client.db( ... );
     
// do something with db
     client
.close();
} );




but client.close() failed. i read some article which suggests to remain the client in the whole life of process. then, how can i check the client is working or broken by some accident?

Jack Macdonald

unread,
Jul 18, 2018, 7:31:00 AM7/18/18
to node-mongodb-native
Should be able to check the result of 
client.isConnected()

See http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#isConnected

Also remember to handle `err` on the callback
Reply all
Reply to author
Forward
0 new messages