title: How can I handle timeout errors in MongoClient?
body: <p>I am connecting a nodejs app to my mongodb database using the following:</p>
  
  <pre><code>const url = 'mongodb://localhost:27017/?replicaSet=rs'
  let client = new MongoClient(url, { 
    useNewUrlParser: true,
    connectTimeoutMS: 60000,    
    socketTimeoutMS: 60000, 
   })
  try {
    let dbclient = await client.connect()
    console.log(dbclient)
    const db = dbclient.db('test')
    const collection = db.collection('accounts')
    const changeStream = collection.watch(pipeline)
    changeStream.on("change", function(change) {
      console.log('changed', change)
    })
  } catch (err) {
    console.log('mongo err:', err)
  }
  </code></pre>
  
  <p>This works perfectly, however it regularly loses connection after a few minutes with the error:</p>
  
  <blockquote>
    <p>Uncaught MongoNetworkError: connection 6 to localhost:27017 timed out</p>
  </blockquote>
  
  <p>According to <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/connecting/connection-settings/" rel="nofollow noreferrer">the documentation</a> it should automatically reconnect up to 30 tries upon error, however it does not appear to make any further attempts to reconnect.</p>
  
  <p>I will also need to run some additional logic on reconnect to properly handle local state.</p>
  
  <p>How can I catch and handle these errors?</p>
  
  <p>Edit: While I'm still not getting other events, I am getting 'reconnect' events after the errors occur. So it seems I can at least react to the errors, but still not actually catch them.</p>