@antelopejs/interface-mongodb
Direct access to the MongoDB client of an AntelopeJS project, for the native operations that the database-agnostic @antelopejs/interface-database does not cover.
What it offers
GetClient()resolves to the project's sharedMongoClientonce the connection is up.- The client is the official Node.js driver, with its full API: CRUD, aggregations, indexes and transactions.
- Every module reuses the one connection that the implementing module opens and configures.
Implementations
| Module | Notes |
|---|---|
@antelopejs/mongodb | Also implements @antelopejs/interface-database |
Install
Add the interface to the module that talks to MongoDB:
pnpm add @antelopejs/interface-mongodb
Then add the implementation to the project:
ajs project modules add @antelopejs/mongodb
Quick start
import { GetClient } from "@antelopejs/interface-mongodb";
export async function countActiveUsers() {
const client = await GetClient();
return await client
.db("myapp")
.collection("users")
.countDocuments({ active: true });
}
Documentation
Compatibility
Requires AntelopeJS core 1.x and the following driver dependency:
| Package | Range |
|---|---|
mongodb | ^6.21.0 |
Contributing
Read CONTRIBUTING.md before you open a pull request. The local checks are:
pnpm install
pnpm lint
pnpm build