How to deploy Mongos

The following steps will guide you through briefly creating a client connection to a sharded MongoDB cluster via mongos, the router for queries and write operations in shared clusters.

You’ll need a Juju environment and a MongoDB application deployed as a sharded cluster.

Deploy and integrate

To deploy mongos and data-integrator, run

juju deploy mongos --channel=6/stable
juju deploy data-integrator --config database-name=<name>
juju deploy mongos-k8s --channel=6/stable --trust
juju deploy data-integrator --config database-name=<name>

Integrate mongos with data-integrator and with the mongodb application running as config-server:

juju integrate mongos data-integrator
juju integrate config-server mongos
juju integrate mongos-k8s data-integrator
juju integrate config-server mongos-k8s

Access the database via mongos

In order to access the integrated database, you will need the mongos URI. To retrieve this, run the following command:

juju run data-integrator/leader get-credentials

You will find the URI under the field uris in the output.

Then SSH into the unit and access the mongo shell:

juju ssh mongos/0
charmed-mongodb.mongosh <URI>
juju ssh --container mongos mongos-k8s/0
mongosh <URI>