title: Closing MongoDB Java Connection
body: <p>I am trying to design a Mongo Db connection class where I am maintaning MongoClient as static.</p>
  
  <pre><code>private static MongoClient client = null;
  
  public static DB connectToMongo() throws Exception {
      if (null != client) {
          return client.getDB(DBNAME);
      }       
      client = new MongoClient(HOST,PORT);                
      return client.getDB(DBNAME);    
  }
  </code></pre>
  
  <p>My whole web application uses the above method to connect to Mongo as follows:</p>
  
  <pre><code>db = MongoDBConnection.connectToMongo();
  collection = db.getCollection("collectionName");
  </code></pre>
  
  <p>After performing DB operations I never call the close connection for MongoClient. The connection class would always return the same instance of MongoClient which is never closed.The only thing I close is cursors. </p>
  
  <ul>
  <li><strong>Is it necessary to close the MongoClient every time we query the database?
  Is my above design valid?</strong></li>
  </ul>