title: How to config connection to mongo database on MongoLab using java mongodb driver, java configuration (not xml configuration)?
body: <p>Currently I'm using Amzone EC2 to host my mongo database, below is code for MongoCongig file in java using java mongodb driver and it's working fine.</p>
  
  <pre><code>@Configuration
  @EnableMongoRepositories
  public class MongoConfig extends AbstractMongoConfiguration
  {
  
      @Value("my_amazone_ec2_host")
      private String host;
  
      @Value("27017")
      private Integer port;
  
      @Value("my_database_name")
      private String database;
  
      @Value("database_admin")
      private String username;
  
      @Value("admin_pass")
      private String password;
  
      @Override
      public String getDatabaseName()
      {
          return database;
      }
  
      @Override
      @Bean
      public Mongo mongo() throws Exception
      {
          return new MongoClient(
                  singletonList( new ServerAddress( host, port ) ),
                  singletonList( MongoCredential.createCredential( username,
                          database, password.toCharArray() ) ) );
      }
  }
  </code></pre>
  
  <p>Now I want to using MongoLab to host my database and MongoLab provide URI to connect to mongo db something like this:</p>
  
  <pre><code>mongodb://&lt;dbuser&gt;:&lt;dbpassword&gt;@ser_num.mongolab.com:port/database_name
  </code></pre>
  
  <p>I tried to modify my host name with this URI but not successful. Can anyone help me config this file?
  I'm using only java configuration, not XML configuration; MongoDB version 3.</p>