Skip to main content
This release is 2 versions behind 0.1.24 — the latest version of @oridune/mongo. Jump to latest
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
23%
Published
a week ago (0.1.22)
class Mongo

Static Properties

protected
abstract
cachingMethods: { provider?: CacheProvider | (string & { }); set: TCacheSetter; get: TCacheGetter; del: TCacheDelete; }
clients: MongoClient[]
models: Map<string, MongoModel<ObjectValidator<any>>>
protected
postConnectEvents: Array<(connectionIndex: number) => void | Promise<void>>
protected
postDisconnectEvents: Array<(connectionIndex: number) => void | Promise<void>>
protected
preConnectEvents: Array<(connectionIndex: number) => void | Promise<void>>
protected
preDisconnectEvents: Array<(connectionIndex: number) => void | Promise<void>>

Static Methods

connect(
urls: string | string[],
options?: MongoClientOptions | MongoClientOptions[],
): Promise<void>
protected
deleteCache(key: string)
disconnect(connectionIndex?: number): Promise<void>
drop(
connectionIndex?: number,
dbName?: string | undefined,
): Promise<void>
dropAll(dbName?: string | undefined): Promise<void>
protected
getCache(key: string)
isConnected(connectionIndex?: number)

Is database connected?

model<T extends ObjectValidator<any>>(
name: string,
schema: T | (() => T),
)
post(
event: "connect" | "disconnect",
callback: (connectionIndex: number) => void | Promise<void>,
)
pre(
event: "connect" | "disconnect",
callback: (connectionIndex: number) => void | Promise<void>,
)
protected
setCache(
key: string,
value: TCacheValue,
ttl?: number,
)
setCachingMethods(options: { provider?: CacheProvider | (string & { }); setter: TCacheSetter; getter: TCacheGetter; deleter: TCacheDelete; }): void
transaction<T>(
callback: (session: ClientSession) => Promise<T>,
opts?:
{ connectionIndex?: number; sessionOpts?: ClientSessionOptions; transactionOpts?: TransactionOptions; sessionEndOpts?: EndSessionOptions; }
| ClientSession
| number
,
connectionIndex?: number,
)

Helper method to execute database transactions

useCaching<T extends TCacheValue>(
callback: () => Promise<T>,
cache?: TCacheOptions,
)

Add Package

deno add jsr:@oridune/mongo

Import symbol

import { Mongo } from "@oridune/mongo";

---- OR ----

Import directly with a jsr specifier

import { Mongo } from "jsr:@oridune/mongo";

Add Package

npx jsr add @oridune/mongo

Import symbol

import { Mongo } from "@oridune/mongo";

Add Package

yarn dlx jsr add @oridune/mongo

Import symbol

import { Mongo } from "@oridune/mongo";

Add Package

pnpm dlx jsr add @oridune/mongo

Import symbol

import { Mongo } from "@oridune/mongo";

Add Package

bunx jsr add @oridune/mongo

Import symbol

import { Mongo } from "@oridune/mongo";