Connecting to a distributed set of MongoDB instances
Accessing data that is stored in a distributed set of MongoDB instances is nearly the same procedure as connecting to a single MongoDB instance.
Before you begin
Enable your application to use MongoDB. See Creating Liberty applications that use MongoDB.
About this task
When you configure the mongo feature in your server.xml file, you 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 master 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.
Procedure
Configure the hostNames and ports in your server.xml file.
<mongo id="mongo1" libraryRef="MongoLib" hostNames="localhost,localhost,localhost" ports="9991,9992,9993"/>