[JAVA-2166] Make it easier to mix ConnectionString settings with MongoClientSettings Created: 04/Apr/16  Updated: 02/Feb/18  Resolved: 02/Feb/18

Status: Closed
Project: Java Driver
Component/s: Async, Configuration
Affects Version/s: None
Fix Version/s: 3.7.0

Type: New Feature Priority: Minor - P4
Reporter: Ross Lawley Assignee: Ross Lawley
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to JAVA-2551 Make it easier to switch between sync... Closed

 Description   

Currently, mixing settings is extremely verbose compared to MongoClientURI.

A recent example is a user (SCALA-243) wanting to set the serverSelectionTimeoutMS in the Scala driver is:

val connectionString = new ConnectionString("mongodb://localhost/?connectTimeoutMS=500&socketTimeoutMS=500")
val mongoClientSettings = MongoClientSettings.builder()
  .clusterSettings(ClusterSettings.builder().applyConnectionString(connectionString).serverSelectionTimeoutMS(500).build())
  .connectionPoolSettings(ConnectionPoolSettings.builder().applyConnectionString(connectionString).build())
  .serverSettings(ServerSettings.builder().build()).credentialList(connectionString.getCredentialList)
  .sslSettings(SslSettings.builder().applyConnectionString(connectionString).build())
  .socketSettings(SocketSettings.builder().applyConnectionString(connectionString).build())
  .build()
    
MongoClient(mongoClientSettings)

Which is very verbose compared to the Sync driver:

String connectionString = "mongodb://localhost/?connectTimeoutMS=500&socketTimeoutMS=500";
MongoClientURI connectionStringAndOptions = new MongoClientURI(connectionString, MongoClientOptions.builder().serverSelectionTimeout(200));
new MongoClient(uriAndOptions); 



 Comments   
Comment by Githook User [ 02/Feb/18 ]

Author:

{'email': 'ross.lawley@gmail.com', 'name': 'Ross Lawley', 'username': 'rozza'}

Message: Improved MongoClientSetting configurability

Added com.mongodb.MongoClientSettings
Updated the Async MongoClientSettings to proxy the new settings.
Added an applyConnectionString method to MongoClientSettings.
Added applyTo[ClusterSettings,ServerSettings,SslSettings,etc..] methods.
Updated com.mongodb.client.MongoClient to use the new settings.

JAVA-2166
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b7dfa1d397ce3cc0baad10e4c8da15a8a0f38c1e

Comment by Mark Paluch [ 17/Jul/17 ]

+1 for ReactiveStreams/RxJava-based drivers. In our case we're overriding only the streamFactoryFactory. MongoClientSettings initialization from ConnectionString would be a good fit, something like MongoClientSettings.builder(ConnectionString).

Generated at Thu Feb 08 08:56:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.