MongoDB

Channel Revision Published Runs on
6/stable 199 04 Oct 2024
Ubuntu 22.04
6/candidate 199 04 Oct 2024
Ubuntu 22.04
6/beta 199 04 Oct 2024
Ubuntu 22.04
6/edge 204 12 Nov 2024
Ubuntu 22.04
5/stable 117 20 Apr 2023
Ubuntu 22.04
5/candidate 117 20 Apr 2023
Ubuntu 22.04
5/edge 139 21 Nov 2023
Ubuntu 22.04 Ubuntu 20.04
5/edge 109 06 Mar 2023
Ubuntu 22.04 Ubuntu 20.04
3.6/stable 100 28 Apr 2023
Ubuntu 20.04 Ubuntu 18.04
3.6/candidate 100 13 Apr 2023
Ubuntu 20.04 Ubuntu 18.04
3.6/edge 100 03 Feb 2023
Ubuntu 20.04 Ubuntu 18.04
juju deploy mongodb --channel 6/beta
Show information

Platform:

Ubuntu
22.04 20.04 18.04

How to scale replicas and shards

In this guide, you will find instructions on how to scale your MongoDB replica set and sharded cluster.

Summary


Scale a replica set

To scale a replica set, simply use juju’s add-unit and remove-unit commands.

Add replicas

To add more replicas, run:

juju add-unit <application_name> -n <num_of_replicas_to_add>

Where an application can be either a bare replica set, shard, or config-server.

Remove replicas

remove-unit allows removing more than one replica so long as they do not constitute the majority of the replicas.

To remove replicas, run:

juju remove-unit <application_name>/<unit_number> <application_name>/<unit_number>

Where an application can be either a bare replica set, shard, or config-server.

Retrieve primary replica

To retrieve the primary replica, use the juju action get-primary:

juju run <application_name>/<unit_number> get-primary

Where an application can be either a bare replica set, shard, or config-server.

Scale a sharded cluster

Add shards to a cluster

To add a shard to a cluster, first deploy the new shard.

To deploy a shard named new-shard, run:

juju deploy mongodb --config role="shard" new-shard -n <number of replicas for shard>

Wait for the shard to show blocked and idle with juju status --watch 1s.

Next, add it to your config-server:

juju integrate <config-server-name>:config-server new-shard:sharding

Remove shards from a cluster

Like official MongoDB, Charmed MongoDB does not support removing the last shard.

To remove a shard named new-shard that is not the last, run:

juju remove-relation <config-server-name>:config-server new-shard:sharding

You can watch your sharded cluster scale down with juju status --watch 1s.

Once the shard is drained, you can fully remove it with:

juju remove-application new-shard