Abimongo
@abimongo/core / Abimongo
Class: Abimongo
Defined in: core/src/lib-core/AbimongoClient.ts:530
Abimongo inherits from AbimongoClient and provides a simplified interface for connecting to MongoDB databases. It allows you to create an instance of Abimongo with a MongoDB URI and optional configuration options.
Extends
Constructors
Constructor
new Abimongo(
uri,options?):Abimongo
Defined in: core/src/lib-core/AbimongoClient.ts:537
Creates an instance of Abimongo.
Parameters
uri
string
The MongoDB connection URI.
options?
Optional configuration options for the client.
Returns
Abimongo
Throws
If the URI is not provided.
Overrides
Properties
_options?
optional_options:AbimongoClientOptions
Defined in: core/src/lib-core/AbimongoClient.ts:54
Inherited from
uri
uri:
string=AbimongoClient.defaultUri
Defined in: core/src/lib-core/AbimongoClient.ts:53
The MongoDB connection URI.
Inherited from
Accessors
client
Get Signature
get client():
MongoClient
Defined in: core/src/lib-core/AbimongoClient.ts:264
Gets the current MongoClient instance.
Returns
MongoClient
The connected MongoClient instance.
An optional MongoClient instance.
Inherited from
db
Get Signature
get db():
Db
Defined in: core/src/lib-core/AbimongoClient.ts:245
Gets the current database instance.
Throws
If the database connection is not established.
Returns
Db
The connected database instance.
Inherited from
Methods
close()
close():
Promise<void>
Defined in: core/src/lib-core/AbimongoClient.ts:455
Closes the MongoDB client connection.
Returns
Promise<void>
A promise that resolves when the client is closed.
Inherited from
collection()
collection<
T>(name):Collection<T>
Defined in: core/src/lib-core/AbimongoClient.ts:319
Retrieves a MongoDB collection by name.
Type Parameters
T
T extends Document
Parameters
name
string
The name of the collection to retrieve.
Returns
Collection<T>
The MongoDB collection instance.
Throws
If the database connection is not established.
Inherited from
connect()
connect():
Promise<Db>
Defined in: core/src/lib-core/AbimongoClient.ts:291
Establishes a connection to the MongoDB database.
Returns
Promise<Db>
A promise that resolves to the connected database instance.
Inherited from
connectDb()
connectDb(
uri,options?):Promise<AbimongoClient>
Defined in: core/src/lib-core/AbimongoClient.ts:108
Connects to the MongoDB database using the provided URI and options.
Parameters
uri
string
The MongoDB connection URI.
options?
Optional configuration options for the client.
Returns
Promise<AbimongoClient>
A promise that resolves to the connected AbimongoClient instance.
Throws
If the URI is not provided.
Inherited from
disconnect()
disconnect():
Promise<void>
Defined in: core/src/lib-core/AbimongoClient.ts:443
Disconnects from the MongoDB database.
Returns
Promise<void>
A promise that resolves when the client is disconnected.
Inherited from
dropCollection()
dropCollection():
Promise<void>
Defined in: core/src/lib-core/AbimongoClient.ts:408
Drops the specified collection from the database.
Returns
Promise<void>
A promise that resolves when the collection is dropped.
Inherited from
dropDatabase()
dropDatabase():
Promise<boolean>
Defined in: core/src/lib-core/AbimongoClient.ts:418
Drops the entire database.
Returns
Promise<boolean>
A promise that resolves to true if the database is dropped successfully, false otherwise.
Inherited from
getClusterInfo()
getClusterInfo():
Promise<{setName?:string;type:string; }>
Defined in: core/src/lib-core/AbimongoClient.ts:349
Retrieves information about the MongoDB cluster type (e.g., standalone, replica set, sharded).
Returns
Promise<{ setName?: string; type: string; }>
A promise that resolves to an object containing the cluster type and set name (if applicable).
Inherited from
getCollection()
getCollection<
T>(name):Collection<T>
Defined in: core/src/lib-core/AbimongoClient.ts:336
Retrieves a MongoDB collection by name, defaulting to the collection specified in the options if not provided.
Type Parameters
T
T extends Document
Parameters
name
string
The name of the collection to retrieve.
Returns
Collection<T>
The MongoDB collection instance.
Throws
If the database connection is not established.
Inherited from
isConnected()
isConnected():
boolean
Defined in: core/src/lib-core/AbimongoClient.ts:463
Checks if the MongoDB client is connected.
Returns
boolean
true if the client is connected, false otherwise.
Inherited from
useCollection()
useCollection(
collectionName):Promise<Collection<any>>
Defined in: core/src/lib-core/AbimongoClient.ts:391
Switches to a different collection at runtime.
Parameters
collectionName
string
The name of the collection to switch to.
Returns
Promise<Collection<any>>
A promise that resolves to the new collection instance.
Throws
If the client is not initialized or the collection name is not provided.
Inherited from
useDatabase()
useDatabase(
dbName):Promise<{client:MongoClient;db:Db; }>
Defined in: core/src/lib-core/AbimongoClient.ts:371
Switches to a different database at runtime (e.g., for multi-tenancy).
Parameters
dbName
string
The name of the database to switch to.
Returns
Promise<{ client: MongoClient; db: Db; }>
A promise that resolves to the new database instance.
Throws
If the client is not initialized or the database name is not provided.
Inherited from
validateUri()
validateUri(
uri):void
Defined in: core/src/lib-core/AbimongoClient.ts:273
Validates the MongoDB URI to ensure it starts with "mongodb://" or "mongodb+srv://".
Parameters
uri
string
The MongoDB connection URI.
Returns
void
Throws
If the URI is invalid.
Inherited from
connect()
staticconnect(uri,options?):Promise<AbimongoClient>
Defined in: core/src/lib-core/AbimongoClient.ts:550
Connects to the MongoDB database using the provided URI and options.
Parameters
uri
string
The MongoDB connection URI.
options?
Optional configuration options for the client.
Returns
Promise<AbimongoClient>
A promise that resolves to the connected AbimongoClient instance.
getAllTenantDBs()
staticgetAllTenantDBs():Promise<Db[]>
Defined in: core/src/lib-core/AbimongoClient.ts:207
Returns
Promise<Db[]>
Inherited from
AbimongoClient.getAllTenantDBs
getDatabase()
staticgetDatabase(tenantId,uri):Promise<{client:MongoClient;db:Db; }>
Defined in: core/src/lib-core/AbimongoClient.ts:132
Retrieves the database connection for a specific tenant.
Parameters
tenantId
string
The ID of the tenant.
uri
string
The MongoDB connection URI.
Returns
Promise<{ client: MongoClient; db: Db; }>
A promise that resolves to the connected database instance.
Throws
If the MongoClient instance is undefined.
Inherited from
getInstance()
staticgetInstance():Abimongo
Defined in: core/src/lib-core/AbimongoClient.ts:558
Retrieves the current Abimongo instance.
Returns
Abimongo
The current Abimongo instance.
getRegisteredModel()
staticgetRegisteredModel(modelName,tenantId,schema?):GetTanantModelParams<Db> &object
Defined in: core/src/lib-core/AbimongoClient.ts:218
Parameters
modelName
string
tenantId
string
schema?
AbimongoSchema<any>
Returns
GetTanantModelParams<Db> & object
Inherited from
AbimongoClient.getRegisteredModel
getTenantDB()
staticgetTenantDB(tenantId):Db
Defined in: core/src/lib-core/AbimongoClient.ts:186
Retrieves the database connection for a specific tenant.
Parameters
tenantId
string
The ID of the tenant.
Returns
Db
The connected database instance.
Throws
If the MongoClient instance is undefined.
Inherited from
handleTopologyEvent()
statichandleTopologyEvent(event):void
Defined in: core/src/lib-core/AbimongoClient.ts:490
Handles MongoDB topology events (e.g., opening, closing).
Parameters
event
The topology event to handle.
TopologyOpeningEvent | TopologyClosedEvent
Returns
void
Inherited from
AbimongoClient.handleTopologyEvent
init()
staticinit():string|Db
Defined in: core/src/lib-core/AbimongoClient.ts:77
Returns
string | Db
Inherited from
runGlobalGC()
staticrunGlobalGC():Promise<void>
Defined in: core/src/lib-core/AbimongoClient.ts:234
Returns
Promise<void>