Class: MongoConnection
Defined in: service-core/src/database/MongoConnection.ts:18
Represents a single named connection to a MongoDB database using the native mongodb driver, including the
registry of all model classes assigned to the connection's datasource.
Note that this class only references the mongodb package via type-only imports and is therefore safe to load
when the optional mongodb peer dependency is not installed.
Constructors
Constructor
new MongoConnection(
name,client,db,entities?,supportsTransactions?):MongoConnection
Defined in: service-core/src/database/MongoConnection.ts:36
Parameters
name
string
client
MongoClient
db
Db
entities?
Iterable<any, any, any>
supportsTransactions?
boolean = false
Returns
MongoConnection
Properties
client
readonlyclient:MongoClient
Defined in: service-core/src/database/MongoConnection.ts:20
The underlying MongoDB client.
db
readonlydb:Db
Defined in: service-core/src/database/MongoConnection.ts:22
The database that this connection is bound to.
name
readonlyname:string
Defined in: service-core/src/database/MongoConnection.ts:24
The name of the datasource that this connection was created for.
supportsTransactions
readonlysupportsTransactions:boolean
Defined in: service-core/src/database/MongoConnection.ts:30
Indicates whether this connection's MongoDB deployment supports multi-document transactions.
Defaults to false.
Accessors
entityClasses
Get Signature
get entityClasses():
any[]
Defined in: service-core/src/database/MongoConnection.ts:85
Returns the list of all model classes registered with this connection.
Returns
any[]
isConnected
Get Signature
get isConnected():
boolean
Defined in: service-core/src/database/MongoConnection.ts:56
Indicates whether or not the connection is currently active.
Returns
boolean
Methods
admin()
admin():
Admin
Defined in: service-core/src/database/MongoConnection.ts:61
Returns the admin interface of the underlying database.
Returns
Admin
close()
close():
Promise<void>
Defined in: service-core/src/database/MongoConnection.ts:68
Closes the connection to the database server.
Returns
Promise<void>
collectionNameFor()
collectionNameFor(
clazz):string
Defined in: service-core/src/database/MongoConnection.ts:78
Returns the name of the collection that records of the given model class are stored in.
Parameters
clazz
any
The model class to resolve the collection name for.
Returns
string
getMongoRepository()
getMongoRepository<
T>(classOrName):MongoRepository<T>
Defined in: service-core/src/database/MongoConnection.ts:119
Returns a repository for performing operations against the collection associated with the given model class.
This is an alias of getRepository provided for compatibility with TypeORM's DataSource interface.
Type Parameters
T
T extends object = any
Parameters
classOrName
any
The model class, or the name of a registered model class, to retrieve a repository for.
Returns
getRepository()
getRepository<
T>(classOrName):MongoRepository<T>
Defined in: service-core/src/database/MongoConnection.ts:94
Returns a repository for performing operations against the collection associated with the given model class.
Type Parameters
T
T extends object = any
Parameters
classOrName
any
The model class, or the name of a registered model class, to retrieve a repository for.
Returns
startSession()
startSession(
options?):ClientSession
Defined in: service-core/src/database/MongoConnection.ts:129
Creates a new client session for performing transactions using the provided options.
Parameters
options?
ClientSessionOptions
The options to start the session with.
Returns
ClientSession
The newly started session.