Connecting to a distributed set of MongoDB instances
Access data stored in a distributed set of MongoDB instances is nearly the same procedure as connecting to a single MongoDB instance.
Enable the application to use MongoDB.
See Create Liberty applications that use MongoDB. Stabilized feature: The mongodb-2.0 feature is stabilized. The MongoDB Java driver versions 2.10.0 to 2.14.2 that the feature supports are no longer in service. Instead of using the mongodb-2.0 feature, create a CDI producer for Mongo. The CDI producer can use any Mongo version that meets your requirements.
When configuring the mongo feature in server.xml, we can pass a collection of hostNames and ports that are either replica set members or sharded mongos servers.
If the host:port combinations are replica set members, the client finds all members and uses the main by default. If the combinations are sharded mongos servers, the client sends all requests to the closest member with the lowest ping time. If the closest member is down, the client automatically fails over to the next server. Configure the hostNames and ports in server.xml.
<mongo id="mongo1" libraryRef="MongoLib" hostNames="localhost,localhost,localhost" ports="9991,9992,9993"/>
We configured a sharded MongoDB configuration.