MongoDB Enterprise HA

Page last updated:

Integrating the Service With Your App

After the creation of the service and the binding of the service to the application, the environment variable VCAP_SERVICES is created. Information about the credentials are stored in this variable as shown here:

  "mongodbent": [
    "credentials": {
     "database": "rs_a2215d2a-5b5d-0909-8d74-532982b72693",
     "database_uri": "mongodb://3RlgLecirkFZxOxI:JYmPwXizSsyspGl0@a2215d2a-5b5d-4501-8d74-532982b72693-0.service.consul:33694,a2215d2a-5b5d-4501-8d74-532982b72693-1.service.consul:33694,a2215d2a-5b5d-4501-8d74-532982b72693-2.service.consul:33694/rs_a2215d2a-5b5d-4501-8d74-532982b72693?replicaSet=rs_a2215d2a-5b5d-4501-8d74-532982b72693",
     "host": "a2215d2a-5b5d-4501-8d74-532982b72693-0.service.consul,a2215d2a-5b5d-4501-8d74-532982b72693-1.service.consul,a2215d2a-5b5d-4501-8d74-532982b72693-2.service.consul",
     "ops_manager_password": "i7r240A3cTQkVMRdw7P4HCWirA2E2xzL!1aA",
     "ops_manager_url": "http://opsmanager.service.consul:8080",
     "ops_manager_user": "llYlttVLBe9T7lmL",
     "password": "JYmPwXizSsyspGl0",
     "port": "33694",
     "replica_set": "rs_a2215d2a-5b5d-4501-8d74-532982b72693",
     "uri": "mongodb://3RlgLecirkFZxOxI:JYmPwXizSsyspGl0@a2215d2a-5b5d-4501-8d74-532982b72693-0.service.consul:33694,a2215d2a-5b5d-4501-8d74-532982b72693-1.service.consul:33694,a2215d2a-5b5d-4501-8d74-532982b72693-2.service.consul:33694/rs_a2215d2a-5b5d-4501-8d74-532982b72693?replicaSet=rs_a2215d2a-5b5d-4501-8d74-532982b72693",
     "username": "3RlgLecirkFZxOxI"
    "label": "mongodbent",
    "name": "mongoentluk",
    "plan": "small3rs",
    "provider": null,
    "syslog_drain_url": null,
    "tags": []

Administrating Your MongoDB Enterprise Instances

To connect to a running MongoDB Enterprise instance with your local development tools, you can use the cf ssh feature of the cf CLI.

Sample Application

Cloud Foundry: Spring Music Example

Version Upgrade and Feature Compatibility

New versions of MongoDB Enterprise will be announced in the newsletter as soon as they are available.

The upgrade to the new version is done through the CF CLI by running the update service command. This command will always upgrade the binaries to the lastest available version. To ensure the compatibility with your application MongoDB provides a feature flag for breaking changes which is called “featureCompatibilityVersion”.

cf update-service <service-name> -c '{"featureCompatibilityVersion":"X.Y"}'

You can either upgrade the service to the new version without changing the feature compatibility or upgrade both.


Assume you have a MongoDB Enterprise with version 3.4.x called my-mongodb-enterprise

To upgrade to the MongoDB Enterprise 3.6.x binaries without enabling the new features (keep featureCompatibility at 3.4) you must run the following command:

cf update-service my-mongodb-enterprise -c '{"featureCompatibilityVersion":"3.4"}'

To upgrade both the MongoDB Enteprise binaries (if not already done) and the feature set to version 3.6, you must run the following command:

cf update-service my-mongodb-enterprise -c '{"featureCompatibilityVersion":"3.6"}'

Plan Upgrade

MongoDB Enterprise service instances can be upgraded to larger plans (downgrading to smaller plans is not possible).

The upgrade to a larger plan is done through the CF CLI by running the update service command.

cf update-service <service-name> -p <new-plan-name>

MongoDB Ops Manager

As a MongoDB Enterprise customer, you receive access to the Ops Manager to see detailed performance metrics and health state.

To connect to the Ops Manager to get insights into your MongoDB, you can use the cf ssh feature of the cf CLI:

cf ssh -L 8080:opsmanager.service.consul:8080 myapp

After forwarding the port you can access Ops Manager under http://localhost:8080 in your browser and login with the Ops Manager user exposed to your application.


Our MongoDB Enterprise offering consists of 3 dedicated VMs configured as a replicaset.

Ops Manager Host Mappings

There is a known bug regarding host mappings. When the deployment overview shows incorrect information, you need to delete the host mappings on http://opsmanager.service.consul:8080/v2/$GROUP_ID#deployment/hostMappingTab. Please replace $GROUP_ID with your actual group ID.

Overview hosts mappings Delete host mapping


On the MongoDB replicaset you will receive the role readWrite@rs_DBNAME.

On the MongoDB Ops Manager you will receive the role Monitoring Admin.

Best Practices for Developers

  • Write concern majority

Please read Replica Set Read and Write Semantics. We recommend a “Write Concern” of majority to avoid Rollbacks During Replica Set Failover.

  • Check Ops Manager metrics regularly

Please check your Ops Manager metrics and graphs regularly. The performance statistics are particularly important after app deployments.

  • Use an application driver maintained by the MongoDB team

It’s critical to find a driver that is well-maintained and stays up to date with the latest MongoDB features.

  • Index early and often

Without question, the most common database performance issue is improper indexing (or a complete lack thereof). Have a look at Indexes docs.

  • Consider a query timeout

MongoDB targets operations for termination if the associated cursor exceeds its allotted time limit. See cursor.maxTimeMS() for more details.

Additional Databases

MongoDB Enterprise offers additional databases on the same replicaset.

The first database is automatically initialized after creating the replicaset. It can be accessed by creating bindings or service-keys on the mongodbent service instance.

A limited number of additional databases can be created on top of each MongoDB Enterprise replicaset. To create an additional database you must first get the GUID of your replicaset:

cf service my-mongodb-enterprise --guid

Then, create a database (where parent_reference is the GUID of your service instance): On Linux: cf create-service mongodbent-database default my-mongodb-enterprise-db -c '{ "parent_reference": "<MONGODBENTCLUSTER_GUID>" }' On Windows PowerShell: cf create-service mongodbent-database default my-mongodb-enterprise-db -c '{ \"parent_reference\": \"<MONGODBENTCLUSTER_GUID>\" }' Please note that databases are competing for resources. Thus, you should limit the number of databases on your production replicasets.

Known limitations:

All bind and unbind operations of additional databases of the same cluster must happen sequentially.


If you want to create backups, and also be able to restore them afterwards, there is an app available that allows for automatic scheduled backups: backman - the appcloud backup manager.

Service instances bound to this app will be automatically backed up, can be downloaded and also restored on-demand.

If you have created additional databases on your cluster, each database must be bound to backman to be backed up.

Please make sure you create a backup, either by manually using mongodump yourself or with backman, before you do major changes to your database.

View the source for this page in GitHub