Skip to content

routier-collection


routier-collection / plugins/mongodb/src / MongoClientDriver

Class: MongoClientDriver

Defined in: plugins/mongodb/src/MongoClientDriver.ts:73

Implements

Constructors

Constructor

new MongoClientDriver(client, databaseName?, options?): MongoClientDriver

Defined in: plugins/mongodb/src/MongoClientDriver.ts:81

Parameters

client

MongoClientLike

databaseName?

string

options?

MongoClientDriverOptions

Returns

MongoClientDriver

Properties

name

readonly name: "mongodb" = "mongodb"

Defined in: plugins/mongodb/src/MongoClientDriver.ts:75

Names the engine, for errors that would otherwise not say which one failed.

Implementation of

MongoDriver.name

Methods

collection()

collection(name): Promise<MongoCollection>

Defined in: plugins/mongodb/src/MongoClientDriver.ts:91

Parameters

name

string

Returns

Promise<MongoCollection>

Implementation of

MongoDriver.collection


transaction()

transaction<T>(work): Promise<T>

Defined in: plugins/mongodb/src/MongoClientDriver.ts:95

Runs work exactly once, atomically, and returns what it returned.

Exactly once is part of the contract, not an accident of the implementation. Mongo's withTransaction helper retries on a transient error and on a commit conflict, and a driver that used it would make this the only backend in the repository that silently repeats a save — SQLite lets SQLITE_BUSY abort, and the same code has to fail the same way everywhere. A driver retries nothing; a conflict reaches the caller.

A driver whose engine cannot offer atomicity — a standalone mongod rejects transactions outright — may run work with an unbound scope, but it has to say so when it is constructed rather than at the first save.

Type Parameters

T

T

Parameters

work

(scope) => Promise<T>

Returns

Promise<T>

Implementation of

MongoDriver.transaction


dropDatabase()

dropDatabase(): Promise<void>

Defined in: plugins/mongodb/src/MongoClientDriver.ts:135

Removes the database. Succeeds when it does not exist.

Returns

Promise<void>

Implementation of

MongoDriver.dropDatabase


close()

close(): Promise<void>

Defined in: plugins/mongodb/src/MongoClientDriver.ts:139

Returns

Promise<void>

Implementation of

MongoDriver.close

Released under the MIT License.