Connection

flitter-orm/src/services/Connection~ Connection

Service to manage and provide access to a MongoDB connection used by the models.

This service is compatible with flitter-di and must be registered under the 'scaffold' name.


Constructor

new Connection()

Extends

Members

(static) name

The name of this service.

_connection :MongoClient

The active MongoDB connection, if there is one.

Type:
  • MongoClient

(private) _di_allow_defer :boolean

If true, the injector will defer the class if the class requests any services that the container is missing. These services are filled in later and added to the prototype and any instances. True by default.

Type:
  • boolean

(private) _di_deferred_instances :Array.<module:flitter-di/src/Injectable~Injectable>

Collection of instances of this class that need to have the deferred service instances injected into them when the deferred services are finally provided.

(private) _di_deferred_services :Array.<string>

List of services that were deferred and not provided at the time of injection.

Type:
  • Array.<string>

Methods

(async) close()

Close the connection to MongoDB.

collection(name) → {Collection}

From the open connection, fetch a collection with the specified name.

Parameters:
Name Type Description
name string
Returns:
Type
Collection

(async) open(url) → {Promise.<mongodb/Connection>}

Open a connection to the MongoDB database defined by the provided url. Stores that connection in this service.

This must be called before models can access the database.

Parameters:
Name Type Description
url string

the MongoDb connect url

Returns:
Type
Promise.<mongodb/Connection>