HA MongoDB services on Stratum use Replica Sets to provide automated failover in the event of a MongoDB node failure. Stratum handles the replica set configuration within your environment, and expose a single connection URI in an environment variable,
Note: The variable may not always be named
DATABASE_URLif the environment also contains more than one database service. There will always also be another variable named after the service, such as
The environment variable’s value follows the format defined by MongoDB. An example connection string:
In the above example, the primary MongoDb node is at
127.0.1.1:27017 and the secondary node is at
myDB will be the default database to connect to. The replica set to connect to is named
You will need to write your application using a client that supports replica sets - official driver list here.
To test your application locally using a replica set, we recommend that you follow the instructions in this blog post. This will give you a local testing environment that is configured very similarly to your HA MongoDB on Stratum.