Getting connection strings

Gen 2

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 Service endpoints section.
  2. The Service endpoints section displays tabs for available connection methods:
  • MongoDB – Shows the connection string, hostnames, ports, database name, authentication source, and replica set for your deployment.
  • CLI – Provides details for connecting by using the IBM CLI.

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 resource service-instance <INSTANCE_NAME_OR_CRN>

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. (--confirm if it works for manager user)
  • If you don't specify an endpoint-type, the connection string returns the public endpoint by default. (--does it return private by default now?)
  • 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. (--still enforced?)

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 that should be used. The user is not restricted or enforced. You have the flexibility to utilize any user available in your deployment.

The API command looks like:

curl -X GET 'https://resource-controller.cloud.ibm.com/v2/resource_instances/{id}' -H "Authorization: Bearer <IAM token>""

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 manager user. Create more users and retrieve connection strings specific to them by using the UI, the (--fix with updated links if needed, verify api link) 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. (--user page needs updates/to be created)

Unlike Gen 1, Gen 2 deployments do not include a pre-provisioned database admin password. To connect, you must create a service credential, which provides the necessary authentication details for your applications.

Gen 2 deployments display only private connection details. Public endpoints are not available.