@antelopejs/interface-mongodb
v0.0.8
Published
AntelopeJS interface for direct access to the shared MongoDB client
Readme
@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.
Part of AntelopeJS, the TypeScript framework where modules depend on contracts and the application chooses the provider. Built by the team behind AntelopeJS DMS.
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 gets the same
MongoClient. The implementing module opens it, configures it, and closes it.
Implementations
| Module | Notes |
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| @antelopejs/mongodb | Also implements @antelopejs/interface-database. Supplies the client in its default owned mode only. |
Install
Add the interface to the module that talks to MongoDB:
pnpm add @antelopejs/interface-mongodbThen add the implementation to the project:
ajs project modules add @antelopejs/mongodbQuick 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
The interface depends on the official MongoDB driver:
| Package | Range |
| --------- | --------- |
| mongodb | ^6.21.0 |
Contributing
Read CONTRIBUTING.md before you open a pull request. The local checks are:
pnpm install
pnpm run checks