{"id":43431,"library":"node-mongodb-fixtures","title":"node-mongodb-fixtures","description":"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.","status":"active","version":"3.2.9","language":"javascript","source_language":"en","source_url":"https://github.com/cdimascio/node-mongodb-fixtures","tags":["javascript","mongodb","fixtures","loader","tests","unit-tests","unloader","schema"],"install":[{"cmd":"npm install node-mongodb-fixtures","lang":"bash","label":"npm"},{"cmd":"yarn add node-mongodb-fixtures","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-mongodb-fixtures","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for MongoDB client operations (loading/unloading connection)","package":"mongodb","optional":false},{"reason":"Used for CLI command parsing","package":"commander","optional":true},{"reason":"Used internally for async flow control","package":"async","optional":false}],"imports":[{"note":"Package is CommonJS-only; no ES module default export. Use require() or await import() with default hack.","wrong":"import Fixtures from 'node-mongodb-fixtures'","symbol":"Fixtures","correct":"const Fixtures = require('node-mongodb-fixtures')"},{"note":"Fixtures is exported as a single constructor function, not a named export. Do not destructure.","wrong":"const { Fixtures } = require('node-mongodb-fixtures')","symbol":"Fixtures (with options)","correct":"const Fixtures = require('node-mongodb-fixtures'); new Fixtures({ mute: true, dir: './fixtures' })"},{"note":"connect() must be called before load(); options like uri are not passed to load().","wrong":"fixtures.load({ uri: 'mongodb://localhost/test' })","symbol":"programmatic usage","correct":"fixtures.connect('mongodb://localhost/test').then(() => fixtures.load())"}],"quickstart":{"code":"const Fixtures = require('node-mongodb-fixtures');\nconst fixtures = new Fixtures({ dir: './fixtures', mute: false });\n\nfixtures\n  .connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useUnifiedTopology: true })\n  .then(() => fixtures.unload())\n  .then(() => fixtures.load())\n  .then(() => fixtures.disconnect())\n  .catch(err => console.error(err));","lang":"javascript","description":"Shows programmatic usage: create Fixtures instance, connect, unload existing data, load fixtures, then disconnect."},"warnings":[{"fix":"Use `new Fixtures({ dir: '...' })` (without uri) then `.connect('mongodb://...')`.","message":"Starting in v3.0.0, the `Fixtures` constructor no longer accepts a `uri` option; you must call `connect()` separately.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Remove `useNewUrlParser` and `useUnifiedTopology` options from connect(); MongoDB driver 5+ uses new behavior by default.","message":"The `useNewUrlParser` and `useUnifiedTopology` options passed to `connect()` are deprecated in the underlying MongoDB driver v5+. They are ignored (no effect) and should be removed.","severity":"deprecated","affected_versions":">=3.2.0"},{"fix":"Set `mute: false` during development to see errors, or implement your own logging via `debug` module.","message":"If you use `mute: true` in the constructor, all console output is suppressed, including error messages from the library.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Name script files like `people_.js` (the collection name before underscore) and ensure they return a function that modifies the collection.","message":"Collection scripts (files ending with `_`) must not be detected as fixture data files; they are executed for side effects only.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Change `new Fixtures('./fixtures')` to `new Fixtures({ dir: './fixtures' })`.","message":"In v2.x, the constructor accepted a `dir` argument; in v3.x it must be passed as an option object `{ dir: './fixtures' }`.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'2023':44 '3.2.9':19 'allow':55 'cadenc':38 'class':50 'cli':8,35 'collect':28,59 'compar':67 'custom':27,63 'differenti':46 'file':26 'first':49 'first-class':48 'fixtur':4,17,25,54,75,82,92 'focus':79 'generat':57 'in-memori':86 'includ':47 'index':31 'inject':62 'irregular':40 'javascript':24,53,90 'json':22 'key':45 'librari':76 'load':66 'loader':93 'loading/unloading':83 'logic':64 'maintain':41 'memori':73,88 'mongodb':3,15,72,91 'mongodb-memory-serv':71 'node':2 'node-mongodb-fixtur':1 'objectid':56 'packag':6,78 'programmat':33 'pure':80 'releas':37 'schema':99 'script':29,60 'server':74,89 'set':10 'similar':69 'support':20,51 'tear':13 'test':16,94,97 'tool':70 'unit':96 'unit-test':95 'unload':98 'usag':36 'version':18","created_at":"2026-06-05T16:59:46.167144+00:00","updated_at":"2026-06-05T16:59:46.167144+00:00","problems":[{"fix":"Use `const Fixtures = require('node-mongodb-fixtures');` then call `new Fixtures()`. For ES modules: `const { default: Fixtures } = await import('node-mongodb-fixtures');`","cause":"Attempted to destructure Fixtures as a named export or used invalid import syntax (e.g., ES module import without default).","error":"TypeError: fixtures.connect is not a function"},{"fix":"Provide an absolute path or set `dir` relative to `process.cwd()`. For example: `new Fixtures({ dir: path.join(__dirname, 'fixtures') })`","cause":"The `dir` option is not set correctly or the path is relative to cwd. Fixtures resolves relative to the current working directory, not the script file.","error":"Error: Cannot find module './fixtures/people.json'"},{"fix":"Include credentials in URI: `mongodb://user:pass@localhost:27017/test?authSource=admin`. Verify MongoDB server authentication settings.","cause":"Connection string does not include credentials or uses wrong auth mechanism (e.g., SCRAM-SHA-1 vs SCRAM-SHA-256).","error":"MongoError: Authentication failed"},{"fix":"Chain `.then()` after `.connect()`: `fixtures.connect(...).then(() => fixtures.load())`.","cause":"`.connect()` returns a Promise/Fixtures instance, but you may have chained incorrectly or used `.load()` before the Promise resolved.","error":"TypeError: fixtures.load is not a function after .connect()"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/cdimascio/node-mongodb-fixtures#readme","github":"https://github.com/cdimascio/node-mongodb-fixtures","docs":null,"changelog":null,"pypi":null,"npm":"node-mongodb-fixtures","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}