Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between mongoclientoptions vs mongoclientsettings

what are the major differences between mongoclientoptions vs mongoclientsettings

Can anyone please give an example and elaborate where to use what with example?

like image 953
Pandit Avatar asked Apr 15 '19 19:04

Pandit


People also ask

What is MongoClientOptions?

@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.

How do I use MongoClientSettings?

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.

What is MongoDB driver legacy?

“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.


1 Answers

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

like image 145
barrypicker Avatar answered Sep 29 '22 03:09

barrypicker