Skip to main content

Abimongo

@abimongo/core v1.1.4


@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?

AbimongoClientOptions

Optional configuration options for the client.

Returns

Abimongo

Throws

If the URI is not provided.

Overrides

AbimongoClient.constructor

Properties

_options?

optional _options: AbimongoClientOptions

Defined in: core/src/lib-core/AbimongoClient.ts:54

Inherited from

AbimongoClient._options


uri

uri: string = AbimongoClient.defaultUri

Defined in: core/src/lib-core/AbimongoClient.ts:53

The MongoDB connection URI.

Inherited from

AbimongoClient.uri

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

AbimongoClient.client


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

AbimongoClient.db

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

AbimongoClient.close


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

AbimongoClient.collection


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

AbimongoClient.connect


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?

AbimongoClientOptions

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

AbimongoClient.connectDb


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

AbimongoClient.disconnect


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

AbimongoClient.dropCollection


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

AbimongoClient.dropDatabase


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

AbimongoClient.getClusterInfo


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

AbimongoClient.getCollection


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

AbimongoClient.isConnected


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

AbimongoClient.useCollection


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

AbimongoClient.useDatabase


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

AbimongoClient.validateUri


connect()

static connect(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?

AbimongoClientOptions

Optional configuration options for the client.

Returns

Promise<AbimongoClient>

A promise that resolves to the connected AbimongoClient instance.


getAllTenantDBs()

static getAllTenantDBs(): Promise<Db[]>

Defined in: core/src/lib-core/AbimongoClient.ts:207

Returns

Promise<Db[]>

Inherited from

AbimongoClient.getAllTenantDBs


getDatabase()

static getDatabase(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

AbimongoClient.getDatabase


getInstance()

static getInstance(): Abimongo

Defined in: core/src/lib-core/AbimongoClient.ts:558

Retrieves the current Abimongo instance.

Returns

Abimongo

The current Abimongo instance.


getRegisteredModel()

static getRegisteredModel(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()

static getTenantDB(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

AbimongoClient.getTenantDB


handleTopologyEvent()

static handleTopologyEvent(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()

static init(): string | Db

Defined in: core/src/lib-core/AbimongoClient.ts:77

Returns

string | Db

Inherited from

AbimongoClient.init


runGlobalGC()

static runGlobalGC(): Promise<void>

Defined in: core/src/lib-core/AbimongoClient.ts:234

Returns

Promise<void>

Inherited from

AbimongoClient.runGlobalGC