stuppie
stuppie

Reputation: 385

How to set MongoClientOptions using a MongoClientURI?

In the current MongoDB Java API (3.0), there is not a MongoClient constructor that accepts a MongoClientURI and a MongoClientOptions [1]. How I set the options for a client built using a URI?

Is there a way to convert a MongoClientURI to a List<ServerAddress> ? Or set the options after construction of the client? The MongoClient(mongoURI).setOptions(options) accepts an int. The documentation for this method doesn't explain what that int is supposed to be [2]

[1] http://api.mongodb.org/java/3.0/com/mongodb/MongoClient.html

[2] http://api.mongodb.org/java/3.0/com/mongodb/Mongo.html#setOptions-int-

Upvotes: 0

Views: 2538

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 312035

Looks like you can use this variant of the MongoClientURI constructor that takes a String URI and a MongoClientOptions.Builder that has methods for setting each option.

Then you can create your MongoClient using the constructor that takes a MongoClientURI.

Upvotes: 3

Related Questions