Charmed MongoDB
- By Canonical Data Platform
- Databases
Channel | Revision | Published | Runs on |
---|---|---|---|
5/stable | 117 | 20 Apr 2023 | |
5/candidate | 117 | 20 Apr 2023 | |
5/edge | 127 | 19 Sep 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 5/stable
You will need Juju 2.9 to be able to run this command. Learn how to upgrade to Juju 2.9.
Deploy universal operators easily with Juju, the Universal Operator Lifecycle Manager.
Platform:
charms.mongodb.v0.mongodb
-
- Last updated 14 Jun 2023
- Revision Library version 0.7
Code for interactions with MongoDB.
Index
class MongoDBConfiguration
Class for MongoDB configuration.
Description
— replset: name of replica set, needed for connection URI. — database: database name. — username: username. — password: password. — hosts: full list of hosts to connect to, needed for the URI.
- tls_external: indicator for use of internal TLS connection.
- tls_internal: indicator for use of external TLS connection.
Methods
MongoDBConfiguration. uri( self )
Description
Return URI concatenated from fields. None
class NotReadyError
Description
Raised when not all replica set members healthy or finished initial sync. 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: MongoDBConfiguration , 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. __enter__( self )
Description
Return a reference to the new connection. None
MongoDBConnection. __exit__( self , object_type , value , traceback )
Description
Disconnect from MongoDB client. None
MongoDBConnection. is_ready( self )
Is the MongoDB server ready for services requests.
Description
Returns: True if services is ready False otherwise. Retries over a period of 60 seconds times to allow server time to start up.
Raises: ConfigurationError, ConfigurationError, OperationFailure
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. create_user( self , config: MongoDBConfiguration )
Create user.
Description
Grant read and write privileges for specified database.
MongoDBConnection. update_user( self , config: MongoDBConfiguration )
Description
Update grants on database. None
MongoDBConnection. set_user_password( self , username , password: str )
Description
Update the password. None
MongoDBConnection. create_role( self , role_name: str , privileges: dict , roles: dict )
Creates a new role.
Arguments
name of the role to be added.
privledges to be associated with the role.
List of roles from which this role inherits privileges.
MongoDBConnection. drop_user( self , username: str )
Description
Drop user. None
MongoDBConnection. get_users( self )
Description
Add a new member to replica set config inside MongoDB. None
MongoDBConnection. get_databases( self )
Description
Return list of all non-default databases. None
MongoDBConnection. drop_database( self , database: str )
Description
Drop a non-default database. None
MongoDBConnection. primary( self )
Description
Returns primary replica host. None