Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MongoDbConnection

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)
    • keep_alive: (optional) enable connection keep alive (default: true)
    • 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) Credential stores to resolve credentials

Hierarchy

  • MongoDbConnection

Implements

  • any
  • any
  • any

Index

Constructors

constructor

  • Creates a new instance of the connection component.

    Returns MongoDbConnection

Properties

Protected _connection

_connection: any

The MongoDB connection object.

Protected _connectionResolver

_connectionResolver: MongoDbConnectionResolver = new MongoDbConnectionResolver()

The connection resolver.

Protected _databaseName

_databaseName: string

The MongoDB database name.

Protected _db

_db: any

The MongoDb database object.

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

The logger.

Protected _options

_options: ConfigParams = new ConfigParams()

The configuration options.

Methods

close

  • close(correlationId: string, callback?: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

getConnection

  • getConnection(): any
  • Returns any

getDatabase

  • getDatabase(): any
  • Returns any

getDatabaseName

  • getDatabaseName(): string
  • Returns string

isOpen

  • isOpen(): boolean
  • Checks if the component is opened.

    Returns boolean

    true if the component has been opened and false otherwise.

open

  • open(correlationId: string, callback?: function): void
  • Opens the component.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

Generated using TypeDoc