Lightweight MongoDB ODM using JavaScript classes and Joi schema validation, targeting Node.js >=8 with MongoDB 3.x. v3.0.4 is current stable, with infrequent releases. Differentiates from Mongoose by being minimal and class-based, and from the native MongoDB driver by providing model abstractions, schema enforcement via Joi, and automatic document instantiation.
npm install mongo-modelsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating a model class with Joi schema, inserting a document, and connecting/disconnecting to MongoDB.
Use mongodb@3.6.x with Node.js >=8, or stay on v2.x if upgrading mongodb.
Always define Customer.collectionName = 'customers' and Customer.schema = joiSchema after the class definition.
Pass the connection object as first argument and options as second: MongoModels.connect({ uri, db }, {}).Use const [doc] = await Model.insertOne(data); or destructure result array.
To get instances, iterate results and manually construct: results.map(doc => new Model(doc)).
Manually validate before updates using Joi.validate or set up hooks.
Use const MongoModels = require('mongo-models');Ensure you have const MongoModels = require('mongo-models'); before class definition.Add Model.collectionName = 'your_collection_name'; after class definition.
Downgrade mongodb to 3.6.x or upgrade mongo-models to a version supporting 4.x.