Registry / database / mongolass

mongolass

JSON →
library4.4.7jsnpmunverified

Mongolass is an elegant MongoDB driver for Node.js that provides a Mongoose-like API with simpler schema definitions, a pure separation of Schema/Model/Entity, and an awesome plugin system. Current stable version is 4.4.7, with a release cadence of about 6-12 months. Key differentiators: optional pure schemas for validation only (not mixed with Model/Entity), powerful plugin hooks (before/after operations), and lightweight design (no heavy middleware overhead). It supports Node.js >=8, ESM and CJS, and is fully compatible with the native MongoDB driver (v3.x).

npm install mongolass
INSTALL
IMPORT
SIG · MONGOLASS
M
mongolass
databasejavascriptv4.4.7
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.

Mongolass
import Mongolass from 'mongolass'
const Mongolass = require('mongolass').default
Mongolass is the default export. In CJS, use 'const Mongolass = require('mongolass')'.
Schema
import { Schema } from 'mongolass'
import Schema from 'mongolass'
Schema is a named export (static property on Mongolass).
Types
import { Types } from 'mongolass'
const Types = require('mongolass').Types
Types contains ObjectId and other MongoDB types. Access via Mongolass.Types or named import.

Creates a Mongolass instance, defines a schema, inserts a document, and queries with sorting.

import Mongolass from 'mongolass'; import { Schema } from 'mongolass'; const mongolass = new Mongolass('mongodb://localhost:27017/test', { dbName: 'test' }); const UserSchema = new Schema('UserSchema', { name: { type: 'string', required: true }, age: { type: 'number', default: 18 } }); const User = mongolass.model('User', UserSchema); User .insertOne({ name: 'Alice', age: 25 }) .exec() .then(result => console.log('Inserted:', result)) .catch(err => console.error('Error:', err)); User .find() .select({ name: 1, age: 1 }) .sort({ name: -1 }) .exec() .then(users => console.log('Users:', users)) .catch(err => console.error('Find Error:', err));
Debug
Known issues
breakingMongolass v4 removed the built-in ObjectId converter; you must explicitly wrap id strings with Mongolass.Types.ObjectId(id).
fix
Use Mongolass.Types.ObjectId('yourIdString') when filtering or inserting by _id.
affects: >=4.0.0
deprecatedThe .exec() method is deprecated in v4. Use .toArray() for find, .next() for findOne, etc. Directly calling .then() without exec() still works.
fix
Replace .exec() with .toArray() for find() or .next() for findOne().
affects: >=4.0.0
gotchaSchema validation runs only on insert/update operations, not on findAndModify or aggregate.
fix
Use insertOne/updateOne with schema validation; for raw aggregation, bypass schema or validate manually.
affects: *
gotchaMongolass uses the native MongoDB driver's collection methods; the query API is chainable but not identical to mongoose.
fix
Check MongoDB driver docs for chainable methods like .limit(), .skip(), .project() instead of .select().
affects: *
deprecatedThe 'dbName' option in connect() is required for multiple DB instances; omitting it defaults to 'admin'.
fix
Always pass { dbName: 'yourdatabase' } in the options object to connect() or constructor.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Mongolass is not a constructor
Importing incorrectly in some environments (e.g., using require('mongolass').default instead of require('mongolass')).
fix
Use: const Mongolass = require('mongolass');
(node:XXXX) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated
Mongolass v4 uses older MongoDB driver discovery engine; not specifying useUnifiedTopology.
fix
Add { useUnifiedTopology: true } to connect options: new Mongolass('uri', { dbName: 'test', useUnifiedTopology: true })
Error: (mongolass) Schema 'UserSchema' has already been registered.
Calling mongolass.model() twice with the same schema name (explicit or auto-generated).
fix
Reuse the model or schema reference, or use different schema names.
TypeError: Cannot read property 'ObjectId' of undefined
Accessing Mongolass.Types before requiring or importing Mongolass fully.
fix
Ensure import/require is correct: const Mongolass = require('mongolass'); const ObjectId = Mongolass.Types.ObjectId;
Upgrade
Version history
4.4.7latest on npm
Audit
Dependencies
mongodbrequiredCore MongoDB driver; Mongolass wraps it for schema and model management
Agent activity
4 hits · last 30 days
node
4
Resources
mongolass — npm install mongolass · libregistry