Skip to content

Rate this page
Thanks for your feedback
Thank you! The feedback has been submitted.

Get free database assistance or contact our experts for personalized support.

Connect your application

You can use the same MongoDB connection URI in your application that you use with mongosh. Any MongoDB driver accepts this URI, so your app connects to Percona Server for MongoDB the same way whether it runs inside the cluster or outside it.

Connection string format

The format depends on whether the cluster is sharded (default) or a replica set only.

Use the mongos service as the host:

mongodb://<username>:<password>@<cluster-name>-mongos.<namespace>.svc.cluster.local/admin?ssl=false

Replace <cluster-name> with your cluster name and <namespace> with the Kubernetes namespace. Get the cluster name with kubectl get psmdb.

Use the replica set service and include the replica set name:

mongodb://<username>:<password>@<cluster-name>-rs0.<namespace>.svc.cluster.local/admin?replicaSet=rs0&ssl=false

Use the same URI in your application code. If TLS is enabled in your cluster, change ssl=false to ssl=true and ensure your client uses the correct CA; see Transport encryption (TLS/SSL).

Where to get the URI parts

Part How to get it
Username and password From the cluster Secret (admin user) or from an application user you created. See Connect to Percona Server for MongoDB for the kubectl commands to read the admin credentials from the Secret.
Cluster name Run kubectl get psmdb -n <namespace>. The name is in the NAME column.
Namespace The namespace where you installed the Operator and database (for example default or mongodb-operator).

Next steps

Get credentials for your app


Last update: March 23, 2026
Created: March 23, 2026