Class: MongoConnection
Defined in: service-core/src/database/MongoConnection.ts:17
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 datastore.
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?):MongoConnection
Defined in: service-core/src/database/MongoConnection.ts:29
Parameters
name
string
client
MongoClient
db
Db
entities?
Iterable<any, any, any>
Returns
MongoConnection
Properties
client
readonlyclient:MongoClient
Defined in: service-core/src/database/MongoConnection.ts:19
The underlying MongoDB client.
db
readonlydb:Db
Defined in: service-core/src/database/MongoConnection.ts:21
The database that this connection is bound to.
name
readonlyname:string
Defined in: service-core/src/database/MongoConnection.ts:23
The name of the datastore that this connection was created for.
Accessors
entityClasses
Get Signature
get entityClasses():
any[]
Defined in: service-core/src/database/MongoConnection.ts:71
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:42
Indicates whether or not the connection is currently active.
Returns
boolean
Methods
admin()
admin():
Admin
Defined in: service-core/src/database/MongoConnection.ts:47
Returns the admin interface of the underlying database.
Returns
Admin
close()
close():
Promise<void>
Defined in: service-core/src/database/MongoConnection.ts:54
Closes the connection to the database server.
Returns
Promise<void>
collectionNameFor()
collectionNameFor(
clazz):string
Defined in: service-core/src/database/MongoConnection.ts:64
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:105
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:80
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.