
MongoDB
- Canonical
- Databases
Channel | Revision | Published | Runs on |
---|---|---|---|
6/stable | 199 | 04 Oct 2024 | |
6/candidate | 199 | 04 Oct 2024 | |
6/beta | 199 | 04 Oct 2024 | |
6/edge | 212 | 12 Mar 2025 | |
5/stable | 117 | 20 Apr 2023 | |
5/candidate | 117 | 20 Apr 2023 | |
5/edge | 139 | 21 Nov 2023 | |
5/edge | 109 | 06 Mar 2023 | |
3.6/stable | 100 | 28 Apr 2023 | |
3.6/candidate | 100 | 13 Apr 2023 | |
3.6/edge | 100 | 03 Feb 2023 |
juju deploy mongodb --channel 6/stable
Deploy universal operators easily with Juju, the Universal Operator Lifecycle Manager.
Platform:
charms.mongodb.v1.mongodb
-
- Last updated 21 Aug 2024
- Revision Library version 1.3
Code for interactions with MongoDB.
Index
class FailedToMovePrimaryError
Description
Raised when attempt to move a primary fails. None
class MongoDBConnection
In this class we create connection object to MongoDB.
Description
Real connection is created on the first call to MongoDB. Delayed connectivity allows to firstly check database readiness and reuse the same connection for an actual query later in the code.
Connection is automatically closed when object destroyed. Automatic close allows to have more clean code.
Note that connection when used may lead to the following pymongo errors: ConfigurationError, ConfigurationError, OperationFailure. It is suggested that the following pattern be adopted when using MongoDBConnection:
with MongoDBConnection(self._mongodb_config) as mongo: try: mongo.<some operation from this class> except ConfigurationError, ConfigurationError, OperationFailure: <error handling as needed>
Methods
MongoDBConnection. __init__( self , config: MongoConfiguration , uri , direct )
A MongoDB client interface.
Arguments
MongoDB Configuration object.
allow using custom MongoDB URI, needed for replSet init.
force a direct connection to a specific host, avoiding reading replica set configuration and reconnection.
MongoDBConnection. init_replset( self )
Create replica set config the first time.
Description
Raises: ConfigurationError, ConfigurationError, OperationFailure
MongoDBConnection. get_replset_status( self )
Get a replica set status as a dict.
Description
Returns: A set of the replica set members along with their status.
Raises: ConfigurationError, ConfigurationError, OperationFailure
MongoDBConnection. get_replset_members( self )
Get a replica set members.
Description
Returns: A set of the replica set members as reported by mongod.
Raises: ConfigurationError, ConfigurationError, OperationFailure
MongoDBConnection. add_replset_member( self , hostname: str )
Add a new member to replica set config inside MongoDB.
Description
Raises: ConfigurationError, ConfigurationError, OperationFailure, NotReadyError
MongoDBConnection. remove_replset_member( self , hostname: str )
Remove member from replica set config inside MongoDB.
Description
Raises: ConfigurationError, ConfigurationError, OperationFailure, NotReadyError
MongoDBConnection. step_down_primary( self )
Description
Steps down the current primary, forcing a re-election. None
MongoDBConnection. move_primary( self , new_primary_ip: str )
Forcibly moves the primary to the new primary provided.
Arguments
ip address of the unit chosen to be the new primary.
MongoDBConnection. set_replicaset_election_priority( self , priority: int , ignore_member: str )
Description
Set the election priority for the entire replica set. None
MongoDBConnection. primary( self )
Description
Returns primary replica host. None
MongoDBConnection. is_any_sync( rs_status: Dict )
Returns true if any replica set members are syncing data.
Arguments
current state of replica set as reported by mongod.
Description
Checks if any members in replica set are syncing data. Note it is recommended to run only one sync in the cluster to not have huge performance degradation.