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

# mongos

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

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

Platform:

24.04

22.04

8/stable 82

```
juju deploy mongos --channel 8/stable
```

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

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

## charms.mongos.v0.upgrade\_helpers

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

    Fetch library

    ```
    charmcraft fetch-lib charms.mongos.v0.upgrade_helpers
    ```

    [Download upgrade\_helpers.py](https://charmhub.io/mongos/libraries/upgrade_helpers/download)
  + *Last updated* 12 Nov 2024
  + *Revision* Library version 0.4

Manager for handling Mongos in-place upgrades.

---

Index

* [def unit\_number(
  unit\_
  )](https://charmhub.io/mongos/libraries/upgrade_helpers#unit_number)
* [class StatusException](https://charmhub.io/mongos/libraries/upgrade_helpers#statusexception)
* + [def \_\_init\_\_(
    self,
    status)](https://charmhub.io/mongos/libraries/upgrade_helpers#statusexception-__init__)
* [class PrecheckFailed](https://charmhub.io/mongos/libraries/upgrade_helpers#precheckfailed)
* + [def \_\_init\_\_(
    self,
    message)](https://charmhub.io/mongos/libraries/upgrade_helpers#precheckfailed-__init__)
* [class FailedToElectNewPrimaryError](https://charmhub.io/mongos/libraries/upgrade_helpers#failedtoelectnewprimaryerror)
* [class ClusterNotHealthyError](https://charmhub.io/mongos/libraries/upgrade_helpers#clusternothealthyerror)
* [class BalancerStillRunningError](https://charmhub.io/mongos/libraries/upgrade_helpers#balancerstillrunningerror)
* [class PeerRelationNotReady](https://charmhub.io/mongos/libraries/upgrade_helpers#peerrelationnotready)
* [class UnitState](https://charmhub.io/mongos/libraries/upgrade_helpers#unitstate)
* [class AbstractUpgrade](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade)
* + [def \_\_init\_\_(
    self,
    charm\_)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-__init__)
* + [def unit\_state(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-unit_state)
* + [def unit\_state(
    self,
    value)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-unit_state)
* + [def is\_compatible(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-is_compatible)
* + [def in\_progress(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-in_progress)
* + [def get\_unit\_juju\_status(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-get_unit_juju_status)
* + [def app\_status(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-app_status)
* + [def versions\_set(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-versions_set)
* + [def set\_versions\_in\_app\_databag(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-set_versions_in_app_databag)
* + [def authorized(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-authorized)
* + [def upgrade\_unit(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-upgrade_unit)
* + [def pre\_upgrade\_check(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#abstractupgrade-pre_upgrade_check)
* [class GenericMongosUpgrade](https://charmhub.io/mongos/libraries/upgrade_helpers#genericmongosupgrade)
* + [def \_\_init\_\_(
    self,
    charm)](https://charmhub.io/mongos/libraries/upgrade_helpers#genericmongosupgrade-__init__)
* + [def is\_mongos\_able\_to\_read\_write(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#genericmongosupgrade-is_mongos_able_to_read_write)
* + [def get\_random\_write\_and\_collection(
    self)](https://charmhub.io/mongos/libraries/upgrade_helpers#genericmongosupgrade-get_random_write_and_collection)
* + [def add\_write\_to\_sharded\_cluster(
    self,
    collection\_name,
    write\_value)](https://charmhub.io/mongos/libraries/upgrade_helpers#genericmongosupgrade-add_write_to_sharded_cluster)
* + [def confirm\_excepted\_write\_cluster(
    self,
    collection\_name,
    expected\_write\_value)](https://charmhub.io/mongos/libraries/upgrade_helpers#genericmongosupgrade-confirm_excepted_write_cluster)
* + [def clear\_tmp\_collection(
    self,
    collection\_name)](https://charmhub.io/mongos/libraries/upgrade_helpers#genericmongosupgrade-clear_tmp_collection)

#### def unit\_number(unit\_: Unit)

Description

Get unit number. None

#### class StatusException

Description

Exception with ops status. None

Methods

StatusException.
\_\_init\_\_(

*self*

,
status: StatusBase
)

#### class PrecheckFailed

Description

App is not ready to upgrade. None

Methods

PrecheckFailed.
\_\_init\_\_(

*self*

,
message: str
)

#### class FailedToElectNewPrimaryError

Description

Raised when a new primary isn't elected after stepping down. None

#### class ClusterNotHealthyError

Description

Raised when the cluster is not healthy. None

#### class BalancerStillRunningError

Description

Raised when the balancer is still running after stopping it. None

#### class PeerRelationNotReady

Description

Upgrade peer relation not available (to this unit). None

#### class UnitState

Description

Unit upgrade state. None

#### class AbstractUpgrade

In-place upgrades abstract class (typing).

Description

Based off specification: DA058 - In-Place Upgrades - Kubernetes v2
(https://docs.google.com/document/d/1tLjknwHudjcHs42nzPVBNkHs98XxAOT2BXGGpP7NyEU/)

Methods

AbstractUpgrade.
\_\_init\_\_(

*self*

,
charm\_: CharmBase
)

AbstractUpgrade.
unit\_state(

*self*
)

Description

Unit upgrade state. None

AbstractUpgrade.
unit\_state(

*self*

,
value: UnitState
)

AbstractUpgrade.
is\_compatible(

*self*
)

Description

Whether upgrade is supported from previous versions. None

AbstractUpgrade.
in\_progress(

*self*
)

Description

Whether upgrade is in progress. None

AbstractUpgrade.
get\_unit\_juju\_status(

*self*
)

Description

Unit upgrade status. None

AbstractUpgrade.
app\_status(

*self*
)

Description

App upgrade status. None

AbstractUpgrade.
versions\_set(

*self*
)

Whether versions have been saved in app databag.

Description

Should only be `False` during first charm install.

If a user upgrades from a charm that does not set versions, this charm will get stuck.

AbstractUpgrade.
set\_versions\_in\_app\_databag(

*self*
)

Save current versions in app databag.

Description

Used after next upgrade to check compatibility (i.e. whether that upgrade should be
allowed).

AbstractUpgrade.
authorized(

*self*
)

Whether this unit is authorized to upgrade.

Description

Only applies to machine charm

AbstractUpgrade.
upgrade\_unit(

*self*
)

Upgrade this unit.

Description

Only applies to machine charm

AbstractUpgrade.
pre\_upgrade\_check(

*self*
)

Check if this app is ready to upgrade.

Description

Runs before any units are upgraded

Does *not* run during rollback

On machines, this runs before any units are upgraded (after `juju refresh`)
On machines & Kubernetes, this also runs during pre-upgrade-check action

Can run on leader or non-leader unit

#### class GenericMongosUpgrade

Description

Substrate agnostif, abstract handler for upgrade events. None

Methods

GenericMongosUpgrade.
\_\_init\_\_(

*self*

,
charm: CharmBase
)

GenericMongosUpgrade.
is\_mongos\_able\_to\_read\_write(

*self*
)

Description

Returns True if mongos is able to read and write. None

GenericMongosUpgrade.
get\_random\_write\_and\_collection(

*self*
)

Description

Returns a tuple for a random collection name and a unique write to add to it. None

GenericMongosUpgrade.
add\_write\_to\_sharded\_cluster(

*self*

,
collection\_name

,
write\_value
)

Description

Adds a the provided write to the provided database with the provided collection. None

GenericMongosUpgrade.
confirm\_excepted\_write\_cluster(

*self*

,
collection\_name: str

,
expected\_write\_value: str
)

Description

Returns True if the replica contains the expected write in the provided collection. None

GenericMongosUpgrade.
clear\_tmp\_collection(

*self*

,
collection\_name: str
)

Description

Clears the temporary collection. None
