Registry / testing / mongodb_fixtures

mongodb_fixtures

JSON →
library1.0.3jsnpmunverified

A simple JSON fixture loader for MongoDB on Node.js that supports loading test data from files, directories, or objects. Version 1.0.3 is the latest stable release with no active development. It provides a CLI tool for quick loading and a programmatic API with methods like load, clear, clearAllAndLoad, and clearAndLoad. Includes a createObjectId helper for managing document references. Differentiators include easy relationship management via keyed documents and support for modifiers. Compatible with Node >= 0.4.1.

npm install mongodb_fixtures
INSTALL
IMPORT
SIG · MONGODB_FIXTURES
M
mongodb_fixtures
testingjavascriptv1.0.3
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
import { createObjectId, connect } from 'pow-mongodb-fixtures'
const fixtures = require('pow-mongodb-fixtures')
The module exports connect and createObjectId; no default export. CommonJS require is typical since this is an older package.
connect
const fixtures = require('pow-mongodb-fixtures').connect('dbname')
import { connect } from 'pow-mongodb-fixtures' // works but require is idiomatic
connect returns a Loader instance. No ES module syntax in original package, but modern bundlers may support.
createObjectId
const createObjectId = require('pow-mongodb-fixtures').createObjectId
import { createObjectId } from 'pow-mongodb-fixtures' // works but require is idiomatic
Helper to generate MongoDB ObjectIds for document references.

Connects to a MongoDB database, clears the 'users' collection, then inserts two documents.

const fixtures = require('pow-mongodb-fixtures').connect('testdb', { host: 'localhost', port: 27017 }); const data = { users: [ { name: 'Alice' }, { name: 'Bob' } ] }; fixtures.clearAndLoad(data, function(err) { if (err) console.error(err); else console.log('Loaded successfully'); process.exit(0); });
Debug
Known issues
gotchaThe 'safe' option defaults to false, meaning writes are not acknowledged by default. This can lead to silent data loss.
fix
Set safe: true in options or ensure you use a callback to handle errors.
affects: >=1.0.0
gotchaThe 'clear' method without arguments drops the entire database, not just collections. This may accidentally delete all data.
fix
Pass explicit collection names to clear only specific collections.
affects: >=1.0.0
deprecatedThis package uses an old version of the MongoDB driver (v1.x) and is not compatible with MongoDB 4.x+.
fix
Migrate to a modern alternative like 'mongodb-memory-server' or 'mongod' for fixture loading.
affects: >=1.0.0
gotchaThe CLI command 'mongofixtures' expects positional arguments in a specific order; missing arguments can cause confusing errors.
fix
Run as: mongofixtures <dbname> <host> <fixture file>
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: fixtures.connect is not a function
Using default import instead of named import with require.
fix
Use const fixtures = require('pow-mongodb-fixtures').connect('dbname');
Error: failed to connect to [localhost:27017]
MongoDB server not running or incorrect host/port.
fix
Start mongod or specify correct host/port in options.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
mongodbrequiredUnderlying MongoDB driver for database operations.
Agent activity
9 hits · last 30 days
node
8
Resources
mongodb_fixtures — npm install mongodb_fixtures · libregistry