Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MongoClientOptions instead of MongoOptions?

I am using MongoOptions class and its methods

setFsync(boolean sync)

setJ(boolean safe)

setW(int val)

setWtimeout(int timeoutMS)

setSafe(boolean isSafe)

How to achieve this using MongoClientOptions as MongoOptions is depracated in Mongo-Java-Driver 3.0. I came to know MongoClientOptions uses

MongoClientOptions.builder()

to create a new Builder instance and then append properties.

like image 790
Dev Avatar asked Mar 31 '15 09:03

Dev


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.


1 Answers

Use the writeConcern method on the builder, as in:

MongoClientOptions options = MongoClientOptions.builder()
                                               .writeConcern(WriteConcern.JOURNALED)
                                               .build();

or

like image 180
jyemin Avatar answered Oct 20 '22 15:10

jyemin