pip_services3_mongodb.connect package

Submodules

Module contents

pip_services3_mongodb.connect.__init__

MongoDbConnectionResolver module initialization.

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_mongodb.connect.MongoDbConnection

Bases: pip_services3_commons.refer.IReferenceable.IReferenceable, pip_services3_commons.refer.IReferences.IReferences, pip_services3_commons.run.IOpenable.IOpenable

MongoDB connection using plain driver.

By defining a connection and sharing it through multiple persistence components you can reduce number of used database connections.

### Configuration parameters ###
  • connection(s): - discovery_key: (optional) a key to retrieve the connection from IDiscovery - host: host name or IP address - port: port number (default: 27017) - uri: resource URI or connection string with all parameters in it

  • credential(s): - store_key: (optional) a key to retrieve the credentials from ICredentialStore - username: (optional) user name - password: (optional) user password

  • options: - max_pool_size: (optional) maximum connection pool size (default: 2) - connect_timeout: (optional) connection timeout in milliseconds (default: 5000) - socket_timeout: (optional) socket timeout in milliseconds (default: 360000) - auto_reconnect: (optional) enable auto reconnection (default: true) - reconnect_interval: (optional) reconnection interval in milliseconds (default: 1000) - max_page_size: (optional) maximum page size (default: 100) - replica_set: (optional) name of replica set - ssl: (optional) enable SSL connection (default: false) - auth_source: (optional) authentication source - debug: (optional) enable debug output (default: false).

### References ###
  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages

  • *:discovery:*:*:1.0 (optional) IDiscovery services

  • *:credential-store:*:*:1.0 (optional) ICredentialStore stores to resolve credentials

close(correlation_id: Optional[str])

Closes component and frees used resources.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

get_connection() pymongo.mongo_client.MongoClient
get_database() pymongo.database.Database
get_database_name() str
is_open() bool

Checks if the component is opened.

Returns

true if the component has been opened and false otherwise.

open(correlation_id: Optional[str])

Opens the component.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

set_references(references: pip_services3_commons.refer.IReferences.IReferences)

Sets references to dependent components.

Parameters

references – references to locate the component dependencies.

class pip_services3_mongodb.connect.MongoDbConnectionResolver

Bases: pip_services3_commons.refer.IReferenceable.IReferenceable, pip_services3_commons.config.IConfigurable.IConfigurable

MongoDbConnectionResolver implementation. Helper class that resolves MongoDB connection and credential parameters, validates them and generates a connection URI.

It is able to process multiple connections to MongoDB cluster nodes.

### Configuration parameters ###
  • connection(s):
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery

    • host: host name or IP address

    • port: port number (default: 27017)

    • database: database name

    • uri: resource URI or connection string with all parameters in it

  • credential(s):
    • store_key: (optional) a key to retrieve the credentials from ICredentialStore

    • username: user name

    • password: user password

### References ###
  • *:discovery:*:*:1.0 (optional) IDiscovery services

  • *:credential-store:*:*:1.0 (optional) ICredentialStore stores to resolve credentials

configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

resolve(correlation_id: Optional[str]) str

Resolves MongoDB connection URI from connection and credential parameters.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

Returns

a resolved URI

set_references(references: pip_services3_commons.refer.IReferences.IReferences)

Sets references to dependent components.

Parameters

references – references to locate the component dependencies.