---
title: Charmhub | Deploy MongoDB using Charmhub - The Open Operator Collection
description: Deploy the latest version of MongoDB on any cloud.
url: https://charmhub.io/mongodb/libraries/shards_interface
---

# MongoDB

[Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")

* [Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")
* [Databases](https://charmhub.io/?filter=databases)

Platform:

24.04

22.04

6/stable 265

```
juju deploy mongodb --channel 6/stable
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/mongodb/libraries/shards_interface#drawer)

## charms.mongodb.v1.shards\_interface

* [*Docstrings*Docstrings](https://charmhub.io/mongodb/libraries/shards_interface)
  [*Code*Source code](https://charmhub.io/mongodb/libraries/shards_interface/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.mongodb.v1.shards_interface
    ```

    [Download shards\_interface.py](https://charmhub.io/mongodb/libraries/shards_interface/download)
  + *Last updated* 09 Oct 2024
  + *Revision* Library version 1.12

In this class, we manage relations between config-servers and shards.

This class handles the sharing of secrets between sharded components, adding shards, and removing
shards.

---

Index

* [class ShardAuthError](https://charmhub.io/mongodb/libraries/shards_interface#shardautherror)
* + [def \_\_init\_\_(
    self,
    shard)](https://charmhub.io/mongodb/libraries/shards_interface#shardautherror-__init__)
* [class RemoveLastShardError](https://charmhub.io/mongodb/libraries/shards_interface#removelastsharderror)
* [class ShardingProvider](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name,
    substrate)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-__init__)
* + [def pass\_sanity\_hook\_checks(
    self,
    event)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-pass_sanity_hook_checks)
* + [def pass\_hook\_checks(
    self,
    event)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-pass_hook_checks)
* + [def add\_shards(
    self,
    departed\_shard\_id)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-add_shards)
* + [def remove\_shards(
    self,
    departed\_shard\_id)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-remove_shards)
* + [def update\_credentials(
    self,
    key,
    value)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-update_credentials)
* + [def update\_mongos\_hosts(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-update_mongos_hosts)
* + [def update\_ca\_secret(
    self,
    new\_ca)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-update_ca_secret)
* + [def get\_config\_server\_status(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-get_config_server_status)
* + [def skip\_config\_server\_status(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-skip_config_server_status)
* + [def get\_shards\_from\_relations(
    self,
    departed\_shard\_id)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-get_shards_from_relations)
* + [def has\_shards(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-has_shards)
* + [def get\_related\_shards(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-get_related_shards)
* + [def get\_all\_sharding\_relations(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-get_all_sharding_relations)
* + [def get\_unreachable\_shards(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-get_unreachable_shards)
* + [def is\_mongos\_running(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-is_mongos_running)
* + [def get\_draining\_shards(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-get_draining_shards)
* + [def cluster\_password\_synced(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#shardingprovider-cluster_password_synced)
* [class ConfigServerRequirer](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-__init__)
* + [def get\_membership\_auth\_modes(
    self,
    event)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_membership_auth_modes)
* + [def update\_member\_auth(
    self,
    event,
    membership\_auth)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-update_member_auth)
* + [def get\_cluster\_passwords(
    self,
    relation\_id)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_cluster_passwords)
* + [def sync\_cluster\_passwords(
    self,
    event,
    operator\_password,
    backup\_password)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-sync_cluster_passwords)
* + [def relation\_created(
    self,
    event)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-relation_created)
* + [def pass\_hook\_checks(
    self,
    event)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-pass_hook_checks)
* + [def pass\_sanity\_hook\_checks(
    self,
    event)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-pass_sanity_hook_checks)
* + [def pass\_tls\_hook\_checks(
    self,
    event)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-pass_tls_hook_checks)
* + [def wait\_for\_draining(
    self,
    mongos\_hosts)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-wait_for_draining)
* + [def get\_relations\_statuses(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_relations_statuses)
* + [def get\_tls\_statuses(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_tls_statuses)
* + [def get\_shard\_status(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_shard_status)
* + [def skip\_shard\_status(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-skip_shard_status)
* + [def drained(
    self,
    mongos\_hosts,
    shard\_name)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-drained)
* + [def update\_password(
    self,
    username,
    new\_password)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-update_password)
* + [def update\_keyfile(
    self,
    key\_file\_contents)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-update_keyfile)
* + [def cluster\_password\_synced(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-cluster_password_synced)
* + [def get\_shard\_members(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_shard_members)
* + [def has\_config\_server(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-has_config_server)
* + [def get\_config\_server\_name(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_config_server_name)
* + [def get\_config\_server\_relation(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_config_server_relation)
* + [def get\_mongos\_hosts(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-get_mongos_hosts)
* + [def is\_ca\_compatible(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-is_ca_compatible)
* + [def is\_shard\_tls\_missing(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-is_shard_tls_missing)
* + [def is\_config\_server\_tls\_missing(
    self)](https://charmhub.io/mongodb/libraries/shards_interface#configserverrequirer-is_config_server_tls_missing)

#### class ShardAuthError

Description

Raised when a shard doesn't have the same auth as the config server. None

Methods

ShardAuthError.
\_\_init\_\_(

*self*

,
shard: str
)

#### class RemoveLastShardError

Description

Raised when there is an attempt to remove the last shard in the cluster. None

#### class ShardingProvider

Description

Manage relations between the config server and the shard, on the config-server's side. None

Methods

ShardingProvider.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
relation\_name: str

,
substrate
)

Description

Constructor for ShardingProvider object. None

ShardingProvider.
pass\_sanity\_hook\_checks(

*self*

,
event: EventBase
)

Description

Returns True if all the sanity hook checks for sharding pass. None

ShardingProvider.
pass\_hook\_checks(

*self*

,
event: EventBase
)

Description

Runs the pre-hooks checks for ShardingProvider, returns True if all pass. None

ShardingProvider.
add\_shards(

*self*

,
departed\_shard\_id
)

Adds shards to cluster.

Description

raises: PyMongoError

ShardingProvider.
remove\_shards(

*self*

,
departed\_shard\_id
)

Removes shards from cluster.

Description

raises: PyMongoError, NotReadyError

ShardingProvider.
update\_credentials(

*self*

,
key: str

,
value: str
)

Description

Sends new credentials, for a key value pair across all shards. None

ShardingProvider.
update\_mongos\_hosts(

*self*
)

Description

Updates the hosts for mongos on the relation data. None

ShardingProvider.
update\_ca\_secret(

*self*

,
new\_ca: str
)

Description

Updates the new CA for all related shards. None

ShardingProvider.
get\_config\_server\_status(

*self*
)

Description

Returns the current status of the config-server. None

ShardingProvider.
skip\_config\_server\_status(

*self*
)

Description

Returns true if the status check should be skipped. None

ShardingProvider.
get\_shards\_from\_relations(

*self*

,
departed\_shard\_id
)

Description

Returns a list of the shards related to the config-server. None

ShardingProvider.
has\_shards(

*self*
)

Description

Returns True if currently related to shards. None

ShardingProvider.
get\_related\_shards(

*self*
)

Description

Returns a list of related shards. None

ShardingProvider.
get\_all\_sharding\_relations(

*self*
)

Description

Returns a list of relation data for related shards. None

ShardingProvider.
get\_unreachable\_shards(

*self*
)

Description

Returns a list of unreable shard hosts. None

ShardingProvider.
is\_mongos\_running(

*self*
)

Description

Returns true if mongos service is running. None

ShardingProvider.
get\_draining\_shards(

*self*
)

Description

Returns the shard that is currently draining. None

ShardingProvider.
cluster\_password\_synced(

*self*
)

Description

Returns True if the cluster password is synced. None

#### class ConfigServerRequirer

Description

Manage relations between the config server and the shard, on the shard's side. None

Methods

ConfigServerRequirer.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
relation\_name: str
)

Description

Constructor for ShardingProvider object. None

ConfigServerRequirer.
get\_membership\_auth\_modes(

*self*

,
event: RelationChangedEvent
)

Description

Returns the available authentication membership forms. None

ConfigServerRequirer.
update\_member\_auth(

*self*

,
event: RelationChangedEvent

,
membership\_auth
)

Description

Updates the shard to have the same membership auth as the config-server. None

ConfigServerRequirer.
get\_cluster\_passwords(

*self*

,
relation\_id: int
)

Description

Retrieves shared cluster passwords. None

ConfigServerRequirer.
sync\_cluster\_passwords(

*self*

,
event: EventBase

,
operator\_password: str

,
backup\_password: str
)

Description

Updates shared cluster passwords. None

ConfigServerRequirer.
relation\_created(

*self*

,
event: RelationJoinedEvent
)

Description

Sets status and flags in relation data relevant to sharding. None

ConfigServerRequirer.
pass\_hook\_checks(

*self*

,
event: EventBase
)

Description

Runs the pre-hooks checks for ConfigServerRequirer, returns True if all pass. None

ConfigServerRequirer.
pass\_sanity\_hook\_checks(

*self*

,
event: EventBase
)

Description

Returns True if all the sanity hook checks for sharding pass. None

ConfigServerRequirer.
pass\_tls\_hook\_checks(

*self*

,
event: EventBase
)

Description

Returns True if the TLS checks for sharding pass. None

ConfigServerRequirer.
wait\_for\_draining(

*self*

,
mongos\_hosts
)

Description

Waits for shards to be drained from sharded cluster. None

ConfigServerRequirer.
get\_relations\_statuses(

*self*
)

Description

Returns status based on relations and their validity regarding sharding. None

ConfigServerRequirer.
get\_tls\_statuses(

*self*
)

Description

Returns statuses relevant to TLS. None

ConfigServerRequirer.
get\_shard\_status(

*self*
)

Returns the current status of the shard.

Description

Note: No need to report if currently draining, since that check block other hooks from
executing.

ConfigServerRequirer.
skip\_shard\_status(

*self*
)

Description

Returns true if the status check should be skipped. None

ConfigServerRequirer.
drained(

*self*

,
mongos\_hosts

,
shard\_name: str
)

Returns whether a shard has been drained from the cluster.

Description

Raises:
ConfigurationError, OperationFailure, ShardNotInClusterError,
ShardNotPlannedForRemovalError

ConfigServerRequirer.
update\_password(

*self*

,
username: str

,
new\_password: str
)

Description

Updates the password for the given user. None

ConfigServerRequirer.
update\_keyfile(

*self*

,
key\_file\_contents: str
)

Description

Updates keyfile on all units. None

ConfigServerRequirer.
cluster\_password\_synced(

*self*
)

Description

Returns True if the cluster password is synced for the shard. None

ConfigServerRequirer.
get\_shard\_members(

*self*
)

Returns a list of shard members.

Description

Raises: PyMongoError

ConfigServerRequirer.
has\_config\_server(

*self*
)

Description

Returns True if currently related to config server. None

ConfigServerRequirer.
get\_config\_server\_name(

*self*
)

Description

Returns the related config server's name. None

ConfigServerRequirer.
get\_config\_server\_relation(

*self*
)

Description

Returns the related config server relation data. None

ConfigServerRequirer.
get\_mongos\_hosts(

*self*
)

Description

Returns a list of IP addresses for the mongos hosts. None

ConfigServerRequirer.
is\_ca\_compatible(

*self*
)

Description

Returns true if both the shard and the config server use the same CA. None

ConfigServerRequirer.
is\_shard\_tls\_missing(

*self*
)

Description

Returns true if the config-server has TLS enabled but the shard does not. None

ConfigServerRequirer.
is\_config\_server\_tls\_missing(

*self*
)

Description

Returns true if the shard has TLS enabled but the config-server does not. None
