Spring with mongo-java-driver Use Azure Cosmos DB as MongoDB

1.2k views Asked by At

I'm trying to use Azure Cosmos DB instead of MongoDB with my Spring boot app.

Currently, I'm using the mongo.host/database/port properties. I couldn't find where I can set the SSL option and replicaSet or alternatively the full client URI.

This is the code they suggesting and it's working, but it's not helping me...

MongoClient mongoClient = new MongoClient(
    new MongoClientURI("mongodb://[user]:[pass]@[host]:[port]/?ssl=true&replicaSet=globaldb"));
1

There are 1 answers

1
Siddhesh Vethe On BEST ANSWER

Can you try just using the "spring.data.mongodb.uri" property instead of specifying the host/database/port separately?

The official documentation (https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-connecting-to-mongodb) also recommends this approach while connecting to replica-sets.

This issue is also discussed at How to configure spring-data-mongodb to use a replica set via properties