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 page, scroll down to the Endpoints section.
  2. Within the Endpoints section, you find a Quick start tab with the following sections:
    • 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 <INSTANCE_NAME_OR_CRN> -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.

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.