Service Instance Access
This page describes usage specific to a9s MongoDB. It builds upon the information provided in Getting Started - Accessing a Service Instance.
Accessing an a9s MongoDB Service Instance
In order to access an a9s MongoDB Service Instance, the Service Instance's credentials stored in the environment variables of the application bound to it. This is further explanined in Lifecycle of a Service Instance - Obtain Credentials for Accessing a Service Instance.
The resulting environment variables for an a9s MongoDB application can be seen below:
$ cf env a9s-mongodb-app
Output
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"
]
}
]
}
}
...
The host, username and password values can be used to connect to the database with a MongoDB client.
Create a Tunnel to The Service
With the cf ssh
command mentioned before, you can create a ssh forward tunnel to the management dashboard. Use port
27017 to connect to the a9s MongoDB Service Instance.
$ cf ssh a9s-mongodb-app -L 27017:d67901c.service.dc1.a9svs:27017
vcap@956aaf4e-6da9-4f69-4b1d-8e631a403312:~$
When the ssh tunnel is open you can access the instance over the address localhost:27017
.
Don't forget to close the session with exit
.
Default Roles
All users, upon creation, are granted the following roles on the default database:
Role | Type | Description |
---|---|---|
collectionModifierRole | Custom role | Grants the user the collMod and compact privileges. |
readWrite | Built-in | Grants the user both read and write privileges. |