class MongoAdapter
implements IDatabaseAdapter
Since 0.1.0

The Mongo adapter — a document-store backend over the native driver.

Constructed by DatabasePlugin for the 'mongodb' arm, and also constructible directly by an application for the 'custom' arm.

Examples

Example 1

import { DatabasePlugin, MongoAdapter } from '@setu-ts/database-plugin';

app.register(DatabasePlugin({
  type: 'mongodb',
  options: { url: 'mongodb://localhost:27017/mydb' },
}));

Constructors

MongoAdapter(options: MongoAdapterOptions)

Creates the adapter.

Parameters

The 'mongodb' arm options; url is required unless client is supplied

Properties

MongoDB snapshot isolation is not the portable serializable guarantee.

Methods

Asserts the adapter is connected before a data operation.

Opens a driver session and calls startTransaction(). A deployment without a replica set fails here, with the driver's own error wrapped in MongoTransactionUnavailableError — never at connect().

connect(): Promise<void>

Establishes the database connection, resolving the client and database name.

Nothing is retained until the connection is fully established: a failure leaves #client null, so the #client !== null guard above does not turn a transient outage into a permanently unusable adapter. Assigning the field first made every later connect() a no-op while isReady() stayed false, so the adapter could never recover.

createDataSource(entity: string): import("@setu-ts/common").IDataSource

Returns a data source for the named entity's collection. @inheritdoc

disconnect(): Promise<void>

Closes the connection and releases the client. @inheritdoc

isReady(): boolean

Reports whether the adapter is connected. @inheritdoc

rawQuery<T>(
_sql: string,
_params?: unknown[]
): Promise<T[]>

Refuses the raw SQL query by name — MongoDB has no SQL — rather than emulating it (the silent-divergence defect M70j closed). The error names the adapter and points at the injected client for native commands.

It rejects, never throws synchronously.