@nestjs-dash/db-seeder-mongodb
v0.2.2
Published
Native MongoDB driver adapter for @nestjs-dash/db-seeder (transactional seeding via client.startSession()/session.withTransaction())
Readme
@nestjs-dash/db-seeder-mongodb
Native mongodb driver adapter for @nestjs-dash/db-seeder: transactional seeding via client.startSession() + session.withTransaction().
Requires the target deployment to be a replica set (or sharded cluster) — a standalone mongod has no transaction support at all, regardless of driver version.
MongoDB has no savepoint concept, so this adapter does not implement partial-commit capability: requesting onRowError: 'skip' against it is rejected with a clear error rather than silently degrading to 'abort'.
Install
pnpm add @nestjs-dash/db-seeder @nestjs-dash/db-seeder-mongodb mongodbUsage
import { createAdapter, resolveTarget } from '@nestjs-dash/db-seeder-mongodb';
import { normalize, runSeeding } from '@nestjs-dash/db-seeder';
const adapter = createAdapter(db); // a mongodb `Db`
// MongoDB is schemaless — omit `schema` for a full passthrough of whatever
// keys are present in the source data, or declare one for validation/coercion.
const target = resolveTarget({ collection: 'events' });
const rows = await normalize({ format: 'json', data: [{ type: 'click' }] }, target);
await runSeeding(adapter, target, rows);License
MIT
