title: Using typesafe's config to manage my database connection
body: <p>This is normally a straight forward problem, but I'm not entirely sure how to solve this in Scala given that it is type sensitive. I have a class where I setup a simple connection to my MongoDB instance. Right now locally, I do the god awful notion of just commenting out the production config lines and uncommenting the local/dev ones. Here's what each one looks like:</p>
  
  <pre><code>// production
  object MongoReplicaConnection {
      def mongoDb = {
        val addresses = List(new ServerAddress("10.1.1.2" , 27017),  new ServerAddress("10.1.1.3" , 27017),  new ServerAddress("10.1.1.4" , 27017))
        val mongoConn = MongoConnection(addresses) 
        val db = mongoConn("mydb")
        db
    }
  }
  
  // local development
  object MongoReplicaConnection {
      def mongoDb = {
        val mongoConn = MongoConnection() 
        val db = mongoConn("mydb_local")
        db
      }
  }
  </code></pre>
  
  <p>In as far as getting the database name passed in, that's trivial - it's just grabbing a string from the config file. Where I'm not able to think of a clean solution is how to handle the fact that I use a List of ServerAddress instances to initialize MongoConnection() vs not passing any List to MongoConnection in a local/dev setup.</p>
  
  <p>How can you use a tool like typesafe's config here? I'm assuming I can just pass an empty List/array to MongoConnection() for a local db connection, but I'm not entirely sure how I can config the production database without modifying the mongoDb function. I've been looking at a tool such as this to help me with the process: <a href="https://github.com/typesafehub/config">https://github.com/typesafehub/config</a></p>