0

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

Mansi Joshi
  • 220
  • 5
  • 16

3 Answers3

3

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.

1

Now my documnetDB connection issue is resolve without SSL, I just have used following code for connection:

mongo.property : mongo.database.uri=mongodb://:@cluster url:27017/?replicaSet=rs0

connection code :

@Bean
    public MongoDbFactory mongoDbFactory() throws UnknownHostException {
       return new SimpleMongoDbFactory(new MongoClientURI(env.getProperty("mongo.database.uri")));
    }

Still I'm having issue with SSL.

Mansi Joshi
  • 220
  • 5
  • 16
0

download this file rds-combined-ca-bundle.pem and keep it in resources section. this link provides great start and it shows sample program for java

GvSharma
  • 2,632
  • 1
  • 24
  • 30