Using a9s MongoDB for PCF

This topic describes how to use a9s MongoDB for PCF after it has been successfully installed. For more information, see the Installing and Configuring a9s MongoDB for PCF topic.

Use a a9s MongoDB for PCF with an Application

To use a9s MongoDB for PCF with an application, create a service instance and bind the service instance to your application. For more information on managing service instances, see Managing Service Instances with the cf CLI.

View the a9s MongoDB for PCF Service

After the tile is installed, you can see the a9s-mongodb and its service plans appear in your PCF marketplace. Run cf marketplace to see the service listing:

$ cf marketplace
Getting services from marketplace in org test / space test as admin...
OK
service      plans                                           description
a9s-mongodb  mongodb-single-small, mongodb-cluster-small,    This is the anynines mongodb 32 service.
             mongodb-single-big, mongodb-cluster-big

For more information on available service plans, see the Configure Service Plans topic.

Create a Service Instance

To provision a MongoDB database, run cf create-service. For example:

$ cf create-service a9s-mongodb mongodb-single-small my-mongodb-service

Depending on your infrastructure and service broker utilization, it may take several minutes to create the service instance.

Run the cf services command to view the creation status. This command displays a list of all your service instances. To view the status of a specific service instance, run cf service NAME-OF-YOUR-SERVICE.

Bind an Application to a Service Instance

After your database is created, run cf bind-service to bind the service to your application:

$ cf bind-service a9s-mongodb-app my-mongodb-service

Restage or Restart Your Application

To enable your application to access the service instance, run cf restage or cf restart to restage or restart your application.

Obtain Service Instance Access Credentials

After a service instance is bound to an application, the credentials of your MongoDB database are stored in the environment variables of the application. Run cf env APP-NAME to display the environment variables.

You can find the credentials in the VCAP_SERVICES key.

$ cf env a9s-mongodb-app
Getting env variables for app a9s-mongodb-app in org test / space test as admin...
OK

System-Provided:
{
 "VCAP_SERVICES": {
  "a9s-mongodb": [
   {
    "credentials": {
     "default_database": "d22906",
     "hosts": [
      "EXAMPLE-HOST"
     ],
     "password": "EXAMPLE-PASSWORD",
     "uri": "EXAMPLE-URI",
     "username": "EXAMPLE-USERNAME"
    },
    "label": "a9s-mongodb",
    "name": "my-mongodb-service",
    "plan": "mongodb-single-small",
    "tags": [
     "nosql",
     "database",
     "document store",
     "eventual consistent"
    ]
   }
  ]
 }
}
...

You can use the host, username, and password values to connect to your database with a MongoDB client.

Delete an a9s MongoDB for PCF Service Instance

Before deleting a service instance, you must backup data stored in your database. This operation cannot be undone and all the data is lost when the service is deleted.

Before you can delete a service instance, you must unbind it from all apps.

List Available Services

Run cf services to list your available services.

$ cf services

Getting services in org test / space test as admin...
OK

name                 service       plan                   bound apps        last operation
my-mongodb-service   a9s-mongodb   mongodb-single-small   a9s-mongodb-app   create succeeded

This example shows that my-mongodb-service is bound to the a9s-mongodb-app application.

Unbind a Service Instance

Run cf unbind-service to unbind the service from your application.

$ cf unbind-service a9s-mongodb-app my-mongodb-service

Delete a Service Instance

After unbinding the service, it is no longer bound to an application. Run cf delete-service to delete the service:

$ cf delete-service my-mongodb-service

It may take several minutes to delete the service. Deleting a service deprovisions the corresponding infrastructure resources. Run the cf services command to view the deletion status.

Upgrade the Service Instance to another Service Plan

Once created, you can upgrade your service instance to another, larger service plan. A larger service plan provides more CPU, RAM and storage. For more information, see the Update a Service Instance of the Managing Service Instances with the cf CLI topic.

$ cf update-service my-mongodb-service -p a-bigger-plan

Here are the plans you can upgrade to depending on the one you are currently using:

  • If you are currently using the mongodb-single-small plan, you can upgrade to the mongodb-single-big plan.

  • If you are currently using the mongodb-cluster-small plan, you can upgrade to the mongodb-cluster-big plan.

Add a Graphite Endpoint

If you want to monitor your service with Graphite, you can set an endpoint to where to information will be sent with the cf update-service command. This command expects the -c flag and a JSON string containing the graphite and metrics_prefix keys.

$ cf update-service my-mongodb-service -c '{ "graphite": ["yourspace.your-graphite-endpoint.com:12345"], "metrics_prefix": "your-api-key.my-cluster-mongo" }'

Add a Syslog Endpoint

The cf update-service command used with the -c flag can let you stream your syslog to a third-party service. In this case, the command expects a JSON string containing the syslog key.

$ cf update-service my-mongodb-service -c '{ "syslog": ["logs4.your-syslog-endpoint.com:54321"] }'
Create a pull request or raise an issue on the source for this page in GitHub