Registry / testing / pow-mongodb-fixtures

pow-mongodb-fixtures

JSON →
library0.14.0jsnpmunverified

A simple fixture loader for MongoDB on Node.js that uses JSON files to define test data. Version 0.14.0 is the latest stable release; the package appears to be in maintenance mode with no recent updates (last publish ~8 years ago). Key differentiators include easy document relationship management (referencing document IDs), support for loading from files or directories, built-in CLI tool, and helpers like clearAndLoad and addModifier. It uses the native MongoDB driver but is not promise-based — all APIs are callback-style.

npm install pow-mongodb-fixtures
INSTALL
IMPORT
SIG · POW-MONGODB-FIXTUR
P
pow-mongodb-fixtures
testingjavascriptv0.14.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Loader
const fixtures = require('pow-mongodb-fixtures').connect('dbname');
import fixtures from 'pow-mongodb-fixtures';
This package is CommonJS-only, not ESM-compatible. Use require() or dynamic import(). The connect() method returns a Loader instance.
createObjectId
const createObjectId = require('pow-mongodb-fixtures').createObjectId;
const { createObjectId } = require('pow-mongodb-fixtures');
createObjectId is a named export from the main module, but destructuring from require may not work depending on module system. Use the full require() call.
fixtures.load
fixtures.load({ users: [{ name: 'test' }] }, function(err) { if (err) throw err; });
fixtures.load({ users: [{ name: 'test' }] });
The load method requires a callback. Omitting it will cause an unhandled error if something fails.

Connects to MongoDB, clears all existing data, and loads user fixtures using clearAllAndLoad.

const fixtures = require('pow-mongodb-fixtures').connect('testdb', { host: 'localhost', port: 27017 }); const data = { users: [ { name: 'Alice' }, { name: 'Bob' } ] }; fixtures.clearAllAndLoad(data, function(err) { if (err) { console.error('Error:', err); } else { console.log('Fixtures loaded successfully!'); } });
Debug
Known issues
breakingAll callback methods (load, clear, etc.) must receive a callback. If omitted, errors may be thrown or become unhandled.
fix
Always provide a callback function to async methods, even if empty.
affects: >=0.0.0
deprecatedThe package uses the callback pattern instead of promises or async/await. No promise wrappers are provided.
fix
Wrap calls in your own promise or use util.promisify to convert to async/await.
affects: >=0.0.0
breakingOptions object in connect() accepts 'safe' which defaults to false. In modern MongoDB drivers, safe mode is not relevant and may cause unexpected behavior.
fix
Set safe: true if you need write acknowledgments, or remove the option to use default driver behavior.
affects: >=0.9.0
Errors
Common errors & fixes
TypeError: fixtures.load is not a function
Calling fixtures.load() before running connect() or using a wrong import path.
fix
Ensure you call connect() first: const fixtures = require('pow-mongodb-fixtures').connect('dbname');
MongoError: no primary server is available
MongoDB server is not running or connection options (host/port) are incorrect.
fix
Start MongoDB (e.g., mongod) or check host/port in connect() call.
Error: callback is required
Calling load, clear, or other async methods without a callback argument.
fix
Provide a callback function as the last argument: load(data, function(err) { ... });
Upgrade
Version history
0.14.0latest on npm
Audit
Dependencies
mongodbrequiredCore dependency to connect and interact with MongoDB
Agent activity
14 hits · last 30 days
node
12
Amazon
1
Resources
pow-mongodb-fixtures — npm install pow-mongodb-fixtures · libregistry