Skip to content

Connect Spring MVC with aws documentDB

I’m using mongoDB with aws ec2 instance it’s working fine and I’ve moved mongoDB to aws documentDB, So i’m not able to connect documentDB with same code, So any one can u please help me if you have idea.

Here is my connection code in Spring MVC:

@Bean
public MongoDbFactory mongoDbFactory() throws UnknownHostException {
   return new SimpleMongoDbFactory(new MongoClient(env.getProperty("mongo.database.host"), Integer.parseInt(env.getProperty("mongo.database.port"))), env.getProperty("mongo.database.name"));
}

Spring, Hibernet and mongoDB version: spring -4.2.5
spring-data-MongoDB -1.10.14
mongo-java-driver -3.5.0

Answer

To connect using TLS, you will have to import the rds-combined-ca-bundle file. I would suggest go through: https://docs.aws.amazon.com/documentdb/latest/developerguide/connect.html and check the sample logic given for java.