IBM Cloud Docs
Getting Connection Strings

Getting Connection Strings

Connection strings allow you to establish a connection between your application and your Databases for MongoDB instance.

Getting Connection Strings in the UI

Follow these steps to retrieve your Databases for MongoDB instance connection strings:

  1. In your deployment's Overview, scroll down to the Endpoints section.
  2. Within the Endpoints section, you find:
    • Connect using a CLI - This section contains information for connecting to your deployment through the IBM CLI.
    • Connect using a MongoDB Enterprise Client - This section allows you to get a TLS certificate and connect to your deployment.

Getting Connection Strings in the CLI

You can also retrieve connection strings using the Cloud Databases CLI plug-in Connection command.

The command looks like this:

ibmcloud cdb deployment-connections example-deployment -u <newusername> [--endpoint-type <endpoint type>]

For more information, see Connections Command options.

Command options

  • If you don't specify a user, the Connections commands return information for the admin user, by default.
  • If you don't specify an endpoint-type, the connection string returns the public endpoint by default.
  • If your deployment has only a private endpoint, specify --endpoint-type private or the commands return an error. The user and endpoint type is not enforced. You can use any user on your deployment with either endpoint (if both exist on your deployment).

Getting Connection Strings in the API

To retrieve users' connection strings from the Cloud Databases API, use the Connections endpoint. To create the connection strings, ensure that the path includes the specific user and endpoint type (public or private) that should be used. The user and endpoint type are not restricted or enforced. You have the flexibility to utilize any user available in your deployment, along with either endpoint (if both are present in your deployment).

The API command looks like:

curl -X GET -H "Authorization: Bearer <>" 'https://api.{region}.databases.cloud.ibm.com/v5/ibm/deployments/{id}/users/{userid}/connections/{endpoint_type}'

Remember to replace {region}, {id}, {userid}, and {endpoint_type} with the appropriate values.

Additional Users and Connection Strings

Access to your Databases for MongoDB deployment is not limited to the admin user. Create more users and retrieve connection strings specific to them by using the UI, the Cloud Databases CLI plug-in, or the Cloud Databases API.

All users on your deployment can use the connection strings, including connection strings for either public or private endpoints.

For more information, see the Managing Users and Roles page.