@SneakyThrows
    private static MongoClientOptions buildMongoDbClientOptions(final BaseMongoDbProperties mongo) {

        var clientOptions = (MongoClientOptions.Builder) null;

        if (StringUtils.isNotBlank(mongo.getClientUri())) {
            val opts = buildMongoClientURI(mongo.getClientUri()).getOptions();
            clientOptions = MongoClientOptions.builder(opts);
        } else {
            clientOptions = MongoClientOptions.builder()
                .writeConcern(WriteConcern.valueOf(mongo.getWriteConcern()))
                .heartbeatConnectTimeout((int) Beans.newDuration(mongo.getTimeout()).toMillis())
                .heartbeatSocketTimeout((int) Beans.newDuration(mongo.getTimeout()).toMillis())
                .maxConnectionLifeTime(mongo.getConns().getLifetime())
                .socketKeepAlive(mongo.isSocketKeepAlive())
                .maxConnectionIdleTime((int) Beans.newDuration(mongo.getIdleTimeout()).toMillis())
                .connectionsPerHost(mongo.getConns().getPerHost())
                .socketTimeout((int) Beans.newDuration(mongo.getTimeout()).toMillis())
                .connectTimeout((int) Beans.newDuration(mongo.getTimeout()).toMillis())
                .sslEnabled(mongo.isSslEnabled());

            if (StringUtils.isNotBlank(mongo.getReplicaSet())) {
                clientOptions.requiredReplicaSetName(mongo.getReplicaSet());
            }
        }
        clientOptions.sslContext(SSLContexts.createSystemDefault());

        BSON.addEncodingHook(ZonedDateTime.class, new BaseConverters.ZonedDateTimeTransformer());

        val codecRegistry = CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(new BaseConverters.ZonedDateTimeCodecProvider()),
            MongoClient.getDefaultCodecRegistry()
        );
        clientOptions.codecRegistry(codecRegistry);
        return clientOptions.build();
    }
@ SneakyThrows private static MongoClientOptions buildMongoDbClientOptions ( final BaseMongoDbProperties mongo ) { var clientOptions = ( MongoClientOptions . Builder ) null ; if ( StringUtils . isNotBlank ( mongo . getClientUri ( ) ) ) { val opts = buildMongoClientURI ( mongo . getClientUri ( ) ) . getOptions ( ) ; clientOptions = MongoClientOptions . builder ( opts ) ; } else { clientOptions = MongoClientOptions . builder ( ) . writeConcern ( WriteConcern . valueOf ( mongo . getWriteConcern ( ) ) ) . heartbeatConnectTimeout ( ( int ) Beans . newDuration ( mongo . getTimeout ( ) ) . toMillis ( ) ) . heartbeatSocketTimeout ( ( int ) Beans . newDuration ( mongo . getTimeout ( ) ) . toMillis ( ) ) . maxConnectionLifeTime ( mongo . getConns ( ) . getLifetime ( ) ) . socketKeepAlive ( mongo . isSocketKeepAlive ( ) ) . maxConnectionIdleTime ( ( int ) Beans . newDuration ( mongo . getIdleTimeout ( ) ) . toMillis ( ) ) . connectionsPerHost ( mongo . getConns ( ) . getPerHost ( ) ) . socketTimeout ( ( int ) Beans . newDuration ( mongo . getTimeout ( ) ) . toMillis ( ) ) . connectTimeout ( ( int ) Beans . newDuration ( mongo . getTimeout ( ) ) . toMillis ( ) ) . sslEnabled ( mongo . isSslEnabled ( ) ) ; if ( StringUtils . isNotBlank ( mongo . getReplicaSet ( ) ) ) { clientOptions . requiredReplicaSetName ( mongo . getReplicaSet ( ) ) ; } } clientOptions . sslContext ( SSLContexts . createSystemDefault ( ) ) ; BSON . addEncodingHook ( ZonedDateTime . class , new BaseConverters . ZonedDateTimeTransformer ( ) ) ; val codecRegistry = CodecRegistries . fromRegistries ( CodecRegistries . fromProviders ( new BaseConverters . ZonedDateTimeCodecProvider ( ) ) , MongoClient . getDefaultCodecRegistry ( ) ) ; clientOptions . codecRegistry ( codecRegistry ) ; return clientOptions . build ( ) ; }
Create a MongoClientOptions object.
<p>
The object will be created from a collection of individual property
settings, or a MongoDb client connection string (uri), or some
combination of the two.
<p>
This is complicated by the fact that the default values provided by
the CAS code in BaseMongoDbProperties.java are not the same as the
default values for the corresponding options provided by the MongoDb
Java driver when it creates a MongoClientOptions object.
<p>
To ensure predictable results in all cases, we initialize the client
options from the individual property settings (even if just the CAS
default values), and then use those values as the starting point to
process the client uri (if one is provided). This way, any options
in the uri will override the earlier ones, but any options missing
from the uri will have the values (default or user-provided) from
the individual property settings.
<p>
This behavior matches the comment in BaseMongoDbProperties.java for
the clientUri property: "If not specified, will fallback onto other
individual settings. If specified, takes over all other settings
where applicable."

@param mongo the property settings (including, perhaps, a client uri)
@return a bean containing the MongoClientOptions object