Skip to content

MongoDBDriver ​

Creates a new MongoDBDriver.

Parameters ​

NameDescription
configConnection configuration options.

MongoDBPreparedStatement ​

Parameters ​

NameDescription
driverThe MongoDBDriver instance.
operationThe operation directive string.

MongoDBDriver ​

MongoDB driver implementation. Handles connection, queries, and MongoDB-specific operations.

MongoDBPreparedStatement ​

MongoDBPreparedStatement wraps a MongoDBDriver operation for deferred execution.

connect ​

Establishes a connection to MongoDB. Builds the URI, configures the client, and selects the database.

returns — Promise<void>

disconnect ​

Closes the MongoDB connection and clears the reference.

returns — Promise<void>

query ​

Executes a MongoDB operation encoded as a string directive. Parses collection, method, and parameters, then dispatches the call.

Parameters ​

NameDescription
operationDirective in the format "collection:method".
paramsParameters object or payload for the operation.

returns — Promise<QueryResult>

prepare ​

Prepares a MongoDB operation for later execution. MongoDB does not support parameterized statements natively, so this wraps the operation directive in a PreparedStatement.

Parameters ​

NameDescription
operationThe operation directive string.

returns — Promise<PreparedStatement>

beginTransaction ​

Begins a transaction context. MongoDB transactions require a replica set or sharded cluster.

returns — Promise<void>

commit ​

Commits the current transaction context.

returns — Promise<void>

rollback ​

Rolls back the current transaction context.

returns — Promise<void>

getLastInsertId ​

Retrieves the last inserted document ID. For MongoDB, this is included in the result of insert operations.

returns — Promise<string | number>

escape ​

Escapes a value for inclusion in logging or introspection. MongoDB uses JSON, so this serializes the value.

Parameters ​

NameDescription
valueAny JavaScript value.

returns — A JSON-stringified representation.

getGrammar ​

Returns the grammar instance for query compilation.

returns — MongoDBGrammar

supportsFeature ​

Determines if the driver supports a given feature.

Parameters ​

NameDescription
featureThe feature name to check.

returns — boolean

buildConnectionUri ​

Builds the MongoDB connection URI.

returns — The MongoDB connection string.

getCollection ​

Returns the MongoDB collection instance by name.

Parameters ​

NameDescription
nameCollection name.

returns — Collection

createIndex ​

Creates an index on a collection.

Parameters ​

NameDescription
collectionCollection name.
keysIndex specification object.
optionsOptional index options.

returns — Promise<void>

dropIndex ​

Drops an index from a collection.

Parameters ​

NameDescription
collectionCollection name.
indexNameName of the index to drop.

returns — Promise<void>

execute ​

Executes the prepared operation with given parameters.

Parameters ​

NameDescription
paramsParameters for the operation payload.

returns — Promise<QueryResult>

close ​

Closes the prepared statement. MongoDB does not require explicit cleanup.

returns — Promise<void>

Released under the MIT License.