Guides
Connection
Connect to your database(s)
Use the exported mongster singleton when your app talks to one database. Reach for MongsterClient when you need multiple client instances or separate connection lifecycles.
Single database applications
import { } from "mongster";
await .("mongodb://127.0.0.1:27017/app", {
: 3,
: 500,
: { : true },
});
const = await .();
await .();Multiple databases or isolated clients
import { , } from "mongster";
const = new ();
const = .({
: .(),
: .().(() => new ()),
});
const = .("events", );
await .("mongodb://127.0.0.1:27017/reporting", {
: { : true },
});
await .({ : true, : false });Connection options that matter most
retryConnection: retry connection attempts before failing.retryDelayMs: base delay between retries.autoIndex: enable or disable index syncing behavior. Use{ syncOnConnect: true }when you want schemas to sync indexes at startup.
Practical guidance
- Connect once during app startup, not on every request.
- Use
getDb()orgetClient()when you need direct driver access. - Use dedicated clients in tests to keep fixtures and databases isolated.