Client
Connect, transact, and work with one or more MongoDB databases
The client layer comes in two forms:
mongster, a shared singleton client,MongsterClient, a class for dedicated client instances.
import { , } from "mongster";
await .("mongodb://127.0.0.1:27017/app");
const = new ();
await .("mongodb://127.0.0.1:27017/reporting");
const = await .();
await .();Main methods
| Method | What it does |
|---|---|
connect(uri?, options?) | Connect to MongoDB and optionally configure retries or auto index sync |
disconnect() | Close the underlying MongoDB client |
ping(dbToPing?) | Check connectivity |
isConnected() | Read the connection flag |
getClient() | Access the raw MongoDB client |
getDb(name?) | Access a database handle |
model(name, schema) | Create a model on this client |
transaction(callback, options?) | Run a MongoDB transaction with automatic cleanup |
startSession(options?) | Create a manual session |
Connection options
retryConnectionretryDelayMsautoIndex
These are layered on top of the MongoDB driver's own connection options.