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.

2. Connect to Percona Server for MongoDB

In this tutorial, you will connect to the Percona Server for MongoDB cluster you deployed previously.

Starting with Operator version 1.23.0, the Operator creates a Secret with a ready-to-use connection string for the databaseAdmin user. Use it to connect to the database.

Here’s how to do it:

  1. List the Secrets objects

    kubectl get secrets -n <namespace>
    

    The connection string Secret is named <cluster_name>-databaseadmin-conn-str. The <cluster_name> value is the name of your Percona Distribution for MongoDB. The default variant is:

    my-cluster-name-databaseadmin-conn-str

    cluster1-databaseadmin-conn-str

  2. Retrieve the connection string. Replace <cluster-name> and <namespace> with your values:

    kubectl get secret <cluster-name>-databaseadmin-conn-str -n <namespace> \
      -o jsonpath='{.data.databaseAdmin_mongos_connectionString}' | base64 --decode && echo
    
    Sample output
    mongodb://databaseAdmin:[email protected]:27017/?authSource=admin
    
    kubectl get secret <cluster-name>-databaseadmin-conn-str -n <namespace> \
      -o jsonpath='{.data.databaseAdmin_rs0_connectionStringSrv}' | base64 --decode && echo
    
    Sample output
    mongodb+srv://databaseAdmin:password123456@my-cluster-name-rs0.mongodb-operator.svc.cluster.local/?authSource=admin&replicaSet=rs0
    

    See Connection secrets for other key names (standard URI, exposed endpoints, custom users).

  3. Run a container with a MongoDB client and connect its console output to your terminal. The following command does this, naming the new Pod percona-client:

    kubectl -n <namespace> run -i --rm --tty percona-client --image=percona/percona-server-mongodb:8.0.26-11 --restart=Never -- bash -il
    
  4. Connect to Percona Server for MongoDB using the connection string from step 2:

    mongosh "<connection-string>"
    
    Example

    The following example connects to the admin database of a Percona Server for MongoDB 8.0 sharded cluster named my-cluster-name in the mongodb-operator namespace:

    mongosh "mongodb://databaseAdmin:databaseAdminPassword@my-cluster-name-mongos.mongodb-operator.svc.cluster.local/admin?authSource=admin"
    

    The exact URI depends on your cluster configuration. Use the value retrieved from the connection string Secret.

Congratulations! You have connected to Percona Server for MongoDB.

Next steps

Insert sample data


Last update: August 3, 2026
Created: August 3, 2026