Documentation for a newer release is available. View Latest

MongoDB Starter

Dependency

The following dependency is provided by default for flo-based projects (created using the Scaffolder)

<dependency>
    <groupId>com.iconsolutions.ipf.core.platform</groupId>
    <artifactId>ipf-common-starter-mongo</artifactId>
</dependency>

If you’re developing your own project using MongoDB as a data store and using Spring Reactive, you can include the above dependency to provide enhanced MongoDB integration.

Doing so adds:

  • Retries

  • SSL Configuration

  • Additional Converters

This page outlines the various different configuration options for the functionality provided by the above dependency.

Retries

When using the MongoDB Starter, the default retry configuration below helps handle transient failures (like network issues or rate limits) in Spring Data Reactive Repositories and can be customised as required.

Config Type Comment Default

ipf.mongodb.max-retry

Integer

Maximum number of retry attempts if error code is contained in the list of retryable-error-codes

3

ipf.mongodb.retryable-error-codes

List of Integers

Comma separated list of error codes for which retries should be attempted

[16500]

ipf.mongodb.delay-duration

Duration

Delay until the next retry attempt, specified as a duration.

For more details on the supported format, see: github.com/lightbend/config/blob/main/HOCON.md#duration-format

500ms

SSL Configuration

If securing a connection to MongoDB server, this can be done by setting the below configuration.

Config Type Comment Default

ipf.mongodb.set-ssl-context

Boolean

Configure the SSL context based on the below configuration parameters

false

ipf.mongodb.ssl-context.key-store-location

String

File path or resource location of the keystore file for MongoDB SSL/TLS connections

n/a

ipf.mongodb.ssl-context.key-store-password

String

Password required to access the keystore defined by ipf.mongodb.ssl-context.key-store-location

You should use secrets rather than storing plain text credentials directly in the property

n/a

ipf.mongodb.ssl-context.key-store-type

String

The type of the keystore defined by ipf.mongodb.ssl-context.key-store-location

n/a

ipf.mongodb.ssl-context.key-password

String

Specifies the password required to access the private key within the keystore.

You should use secrets rather than storing plain text credentials directly in the property

n/a

ipf.mongodb.ssl-context.trust-store-location

String

File path or resource location of the trust store used to establish trust for SSL/TLS connections to MongoDB

n/a

ipf.mongodb.ssl-context.trust-store-type

String

The type of the truststore defined by ipf.mongodb.ssl-context.trust-store-location

n/a

ipf.mongodb.ssl-context.trust-store-password

String

Password to access the trust store file.

You should use secrets rather than storing plain text credentials directly in the property

n/a

Additional Converters

The following additional converters are registered as MongoCustomConversions with Spring Data when adding the ipf-common-starter-mongo dependency:

Converter Conversion

Decimal128ToBigDecimalConverter

source.bigDecimalValue()

BigDecimalToDecimal128Converter

new Decimal128(source)

Decimal128 is a mongo bson type

DateToOffsetDateTimeConverter

ofInstant(source.toInstant(), ZoneOffset.UTC)

OffsetDateTimeToDateConverter

Date.from(source.toInstant())

DateToIsoDateTimeConverter

new IsoDateTime(source.toInstant().atOffset(ZoneOffset.UTC))

IsoDateTimeToStringConverter

source.getDateTimeString()

StringToIsoDateTimeConverter

new IsoDateTime(source)

CommandIdToStringConverter

SerializationHelper.objectToString(source)

StringToCommandIdConverter

SerializationHelper.stringToObject(s, CommandId.class)

SupportingContextToStringConverter

SerializationHelper.objectToString(source)

StringToSupportingContextConverter

SerializationHelper.stringToObject(s, SupportingContext.class)