title: Mongo TypeError: MongoClient.close is not a function
body: <p>I'm building an application that closes it's database connection after a certain time of inactivity. The problem is, I can't kill it's connection with MongoClient.close() because it's always returns that a error "TypeError: MongoClient.close is not a function". What am I doing wrong?</p>
  
  <pre><code>const MongoClient = require("mongodb").MongoClient;
  let mongo = {};
  let db;
  let disconnectTimer;
  let retryTimer;
  let disconnect; //Used to prevent mongo from reconnect.
  
  mongo.disconnect = () =&gt; {
      disconnect = true;
      try {
          MongoClient.close();
      } catch (error) {
          console.warn("Error closing connection to Database =", error);
          throw {
              statusCode: 404,
              error: error.toString(),
              reason: "",
              details: ""
          };
      }
  }
  mongo.getDB = () =&gt; {
      if (typeof db !== "undefined" &amp;&amp; !disconnect)
          return db;
      else
          return connect().catch((error) =&gt; {
              throw error
          }).then((db) =&gt; {return db});
  }
  
  module.exports = mongo;
  </code></pre>