A package and CLI for setting up and tearing down MongoDB test fixtures. Version 3.2.9 supports both JSON and JavaScript fixture files, custom collection scripts for indexes, and programmatic or CLI usage. Release cadence is irregular, maintained as of 2023. Key differentiators include first-class support for JavaScript fixtures (allowing ObjectId generation) and 'collection scripts' for injecting custom logic during load. Compared to similar tools (mongodb-memory-server, fixtures libraries), this package focuses purely on fixture loading/unloading with no in-memory server.
npm install node-mongodb-fixturesNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows programmatic usage: create Fixtures instance, connect, unload existing data, load fixtures, then disconnect.
Use `new Fixtures({ dir: '...' })` (without uri) then `.connect('mongodb://...')`.Remove `useNewUrlParser` and `useUnifiedTopology` options from connect(); MongoDB driver 5+ uses new behavior by default.
Set `mute: false` during development to see errors, or implement your own logging via `debug` module.
Name script files like `people_.js` (the collection name before underscore) and ensure they return a function that modifies the collection.
Change `new Fixtures('./fixtures')` to `new Fixtures({ dir: './fixtures' })`.Use `const Fixtures = require('node-mongodb-fixtures');` then call `new Fixtures()`. For ES modules: `const { default: Fixtures } = await import('node-mongodb-fixtures');`Provide an absolute path or set `dir` relative to `process.cwd()`. For example: `new Fixtures({ dir: path.join(__dirname, 'fixtures') })`Include credentials in URI: `mongodb://user:pass@localhost:27017/test?authSource=admin`. Verify MongoDB server authentication settings.
Chain `.then()` after `.connect()`: `fixtures.connect(...).then(() => fixtures.load())`.