A TypeScript library providing MongoDB repositories with a unit-of-work abstraction for transaction-scoped operations. Current stable version is 3.0.0, released on an active cadence. It wraps the MongoDB Node.js driver (7.x) and offers BaseRepository with CRUD methods, pagination, aggregation, and audit fields via AuditableRepository. Key differentiators include first-class transaction support without boilerplate, per-repository transaction opt-out, structured logging, and an event emitter for change notifications. Requires Node.js >=20.19.0 and a MongoDB replica set or sharded cluster for transactions.
npm install mongo-unit-of-workNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates a complete workflow: connect, create repositories, add a document, commit, and clean up.
Upgrade Node.js to version 20.19.0 or later
Install mongodb@^7.0.0 as a dependency
Check upcoming release notes or migrate to new logging API if available
Use a replica set for development (e.g., run mongod with --replSet rs0 and initiate via rs.initiate())
Ensure all repository names passed to getRepository are defined in the factory object
Run 'npm install mongo-unit-of-work mongodb'
Use named import: import { UnitOfWork } from 'mongo-unit-of-work'Create a new UnitOfWork for each transaction scope or reset after commit/rollback
Ensure 'await client.connect();' runs before creating UnitOfWork