what are the major differences between mongoclientoptions vs mongoclientsettings
Can anyone please give an example and elaborate where to use what with example?
@Immutable public class MongoClientOptions extends Object. Various settings to control the behavior of a MongoClient . Note: This class is a replacement for MongoOptions , to be used with MongoClient . The main difference in behavior is that the default write concern is WriteConcern.
To create a MongoClientSettings object, use the MongoClientSettings. builder() method and chain methods to specify your settings. After chaining them, use the build() method to create the MongoClientSettings object. Adds a listener for command events.
“The MongoDB Legacy driver mongodb-driver-legacy is the legacy synchronous Java driver whose entry point is com. mongodb. MongoClient and central classes include com. mongodb. DB , com.
The short answer from what I can tell is the MongoClientOptions
is the old way, whereas MongoClientSettings
is the new way.
The newest MongoDB Java driver (3.9 at time of writing this answer) supports the old client - i.e., com.mongodb.MongoClient() which takes as a parameter MongoClientOptions. See https://mongodb.github.io/mongo-java-driver/3.9/javadoc/com/mongodb/MongoClient.html.
The newer client has a different namespace - it is com.mongodb.client.MongoClient(). This client expects to be built using com.mongodb.client.MongoClients.create(), which takes a MongoClientSettings. See https://mongodb.github.io/mongo-java-driver/3.9/javadoc/com/mongodb/client/MongoClients.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With