title: Connection to MongoDB using Morphia (Java)
body: <p>I am developing a Java Restful web application and planning to use MongoDB with Morphia as ODM . As I am new to MongoDB, I needed a few suggestions.</p>
  
  <ol>
  <li><p>The best way to handle db connections is to make use of db connection pool, which mongoClient takes care of. </p>
  
  <pre><code>Morphia morphia = new Morphia();   
  ServerAddress addr = new ServerAddress("127.0.0.1", 27017);  
  String databaseName = "test";  
  MongoClient mongoClient = new MongoClient(addr);  
  Datastore datastore = morphia.createDatastore(mongoClient, databaseName); 
  </code></pre></li>
  </ol>
  
  <p>So I need to reuse the above datastore and not create a new instance upon every request as it can waste a lot of resources and affect performance. Should I be implementing the above as singleton class? Can someone help me through this?</p>
  
  <ol start="2">
  <li>Also can someone explain as to how I can set up configuration for db connections such as max connections per host, connection timeout in Morphia using MongoClientOptions?</li>
  </ol>