Creating and Binding MongoDB Service Instances

This topic describes how developers create and bind instances of the MongoDB Enterprise Service for Pivotal Cloud Foundry (PCF).

After deploying the MongoDB Enterprise Service for PCF tile, the MongoDB Enterprise Service appears in the Marketplace. Developers can use either the Cloud Foundry Command Line Interface (cf CLI) or Apps Manager to create an instance of the service and bind it to apps. Binding instances creates unique credentials for each app to access the database.

Create and Bind a Service Instance with the cf CLI

To create and bind an instance of the MongoDB Enterprise Service with the cf CLI, perform the following steps:

  1. Set your API endpoint to the Cloud Controller of your deployment.
    $ cf api api.YOUR-SYSTEM-DOMAIN
    Setting api endpoint to api.YOUR-SYSTEM-DOMAIN...
    OK
    API endpoint:  https://api.YOUR-SYSTEM-DOMAIN (API version: 2.59.0)
    Not logged in. Use 'cf login' to log in.
    
  2. Log in to your deployment and select an org and a space.
    $ cf login
    API endpoint: https://api.YOUR-SYSTEM-DOMAIN
    Email> user@example.com
    Password>
    
  3. List the Marketplace services and locate the MongoDB Enterprise Service.

    $ cf marketplace
    Getting services from marketplace in org example / space development as user@example.com...
    OK

    service plans description mongodb-odb standalone, single_replica_set, sharded_cluster MongoDB Enterprise Service

  4. Create an instance of the MongoDB Enterprise Service. Select either the standalone, replica_set, or sharded_cluster service plan. The standalone plan provides a single node cluster of MongoDB, the replica_set plan provides a three-node replica set, and the sharded_cluster provides a sharded cluster with two shards. For details on different sharded cluster configurations, see Advanced Configuration for MongoDB Versions and Sharded Clusters. The example below uses the standalone plan.

    $ cf create-service mongodb-odb standalone YOUR-SERVICE-INSTANCE
    Creating service instance YOUR-SERVICE-INSTANCE in org example / space development as user@example.com...
    OK
    
  5. Before binding the app, first check that the service was created. You can do this by using cf service INSTANCE_NAME. It will also give you a URL to the MongoDB Ops Manager group that contains the cluster so you can jump to MongoDB Ops Manager and manage, monitor, and backup the cluster.

    $ cf service YOUR-SERVICE-INSTANCE

    Service instance: YOUR-SERVICE-INSTANCE Service: mongodb-odb Bound apps: Tags: Plan: standalone Description: MongoDB Service Documentation url: Dashboard: http://ec2-54-191-73-144.us-west-2.compute.amazonaws.com:8080/v2/595e8e04339ea10b5650eecb

    Last Operation Status: create succeeded Message: Instance provisioning in progress Started: 2017-07-06T19:22:44Z Updated: 2017-07-06T19:24:49Z

  6. Bind the instance to an app.

    $ cf bind-service YOUR-APP YOUR-SERVICE-INSTANCE
    Binding service YOUR-SERVICE-INSTANCE to app YOUR-APP in org example / space development as user@example.com...
    OK
    TIP: Use 'cf restage YOUR-APP' to ensure your env variable changes take effect
    

  7. Restage the app for the binding to take effect.

    $ cf restage YOUR-APP
    

Advanced Configuration for MongoDB Versions and Sharded Clusters

Any plan can be configured to generate any supported version of MongoDB, community and enterprise, by supplying the "version" configuration parameter to the create-service command. For the MongoDB version, type in the actual version number, and for enterprise, add -ent at the end. For example:

    $ cf create-service mongodb-odb standalone my-db -c '{"version": "3.4.5-ent"}' 

For a sharded cluster, the following configuration parameters can be supplied to determine the topology of the cluster to be provisioned:

  • shards — determines the number of shards
  • replicas — determines the number of replicas in each shard
  • config_servers — determines the number of config servers
  • mongos — determines the number of mongos’

The following example will provision a MongoDB sharded cluster with 3 shards, 3-node replica sets in each shard, 3 config servers, and 2 mongos processes:

    $ cf create-service mongodb-odb sharded_cluster my-sharded-db -c '{"shards": 3, "replicas": 3, "config_servers": 3, "mongos": 2}' 

Create and Bind a Service Instance in Apps Manager

To create and bind an instance of the MongoDB Enterprise Service in Apps Manager, perform the following steps:

  1. Navigate to apps.YOUR-SYSTEM-DOMAIN in a browser and log in.
  2. Click Marketplace in the left navigation.
  3. Click MongoDB Enterprise Service.
  4. Select either the standalone, replica_set, or sharded_cluster service plan. The standalone plan provides a single node cluster of MongoDB, the replica_set plan provides a three-node cluster, and the sharded_cluster provides a sharded cluster with 2 shards by default (see above for different configurations).
  5. Enter an Instance Name and select a space under Add to Space. To bind the service instance to an app, select an app under Bind to App.
  6. Click Add. You can also bind an app to a service instance by navigating to the app page, clicking Services, then clicking Bind a Service.
  7. Select a service instance to bind to the app and click Bind.
Create a pull request or raise an issue on the source for this page in GitHub