Registry / database / wires-mongo

wires-mongo

JSON →
library1.6.61jsnpmunverified

An ambitious ORM for MongoDB for Node.js, built on top of wires-domain service injection. Current stable version is 1.6.61. It provides model mapping, automatic join queries, schema validation with required, unique, min/max length, custom validators, and text index creation. Unlike Mongoose, it focuses on simplicity and promises, requiring manual connection setup via a domain service and supporting MongoDB 2.x-3.x. Release cadence is irregular with infrequent updates.

npm install wires-mongo
INSTALL
IMPORT
SIG · WIRES-MONGO
W
wires-mongo
databasejavascriptv1.6.61
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.

Model
const Model = require('wires-mongo');
import Model from 'wires-mongo';
wires-mongo does not support ESM imports; use CommonJS require().
domain
const domain = require('wires-domain');
const domain = require('wires-mongo');
wires-domain is a separate package needed for service injection.
default (Model.extend)
const MyModel = Model.extend({ collection: 'posts', schema: { ... } });
class MyModel extends Model { ... }
Model is used via .extend() factory, not class inheritance.

Shows how to set up a connection via wires-domain, define a model with schema, and save a document.

const domain = require('wires-domain'); const Model = require('wires-mongo'); const mongo = require('mongodb'); domain.service('$db', function() { return new Promise((resolve, reject) => { mongo.MongoClient.connect('mongodb://localhost:27017/test', (err, db) => { if (err) return reject(err); resolve(db); }); }); }); const User = Model.extend({ collection: 'users', schema: { _id: {}, name: { required: true }, email: {} } }); const user = new User({ name: 'Alice', email: 'alice@example.com' }); user.save().then(() => console.log('Saved'));
Debug
Known issues
breakingwires-mongo requires wires-domain for database connection; no built-in connector.
fix
Install wires-domain and register a '$db' service that returns a MongoClient connection.
affects: >=0.0.0
gotcharequired validation with boolean 'true' only checks for undefined, not null or empty string.
fix
Use a function validator to check for null or empty values.
affects: >=0.0.0
deprecatedPackage uses callback-based MongoClient.connect() and auto_reconnect option, deprecated in MongoDB 3.x.
fix
Use MongoClient.connect() with promise or use native driver's newer options.
affects: >=0.0.0
gotchaIndex creation with createAllIndexes() only works if the model is already saved; otherwise may fail silently.
fix
Ensure collection exists before calling createAllIndexes().
affects: >=0.0.0
gotchaunique validation applies only to arrays, not scalar fields.
fix
Use MongoDB index for scalar unique constraints.
affects: >=0.0.0
Errors
Common errors & fixes
ReferenceError: domain is not defined
Missing require('wires-domain').
fix
Install and require wires-domain before using wires-mongo.
TypeError: Model.extend is not a function
Incorrect import: wires-mongo exports the Model constructor directly, not as a property.
fix
Use const Model = require('wires-mongo');
MongoError: not authorized on admin to execute command
Wrong database permissions or connection string.
fix
Ensure the connected user has readWrite permissions on the target database.
ValidationError: name is required
Trying to save a document without required field 'name'.
fix
Set name property before saving.
TypeError: Cannot read property 'collection' of undefined
Missing $db service or invalid connection.
fix
Check that wires-domain is configured and the MongoDB server is running.
Upgrade
Version history
1.6.61latest on npm
Audit
Dependencies
wires-domainrequiredRequired for database connection service registration
Agent activity
22 hits · last 30 days
node
18
Meta
2
OpenAI (training)
1
Resources
wires-mongo — npm install wires-mongo · libregistry