Registry / database / classy-mongo

classy-mongo

JSON →
library0.0.14jsnpmunverified

Classy Mongo (v0.0.14) is a lightweight, class-based ODM for MongoDB, providing a simple way to define models using ES6 classes with property prototypes for schema definition. It offers methods like `findById`, `insertOne`, and static query helpers. Released infrequently, it is a minimal alternative to Mongoose, suitable for small projects or prototypes.

npm install classy-mongo
INSTALL
IMPORT
SIG · CLASSY-MONGO
C
classy-mongo
databasejavascriptv0.0.14
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.

default export
✓ import classy from 'classy-mongo'
✗ const classy = require('classy-mongo')
The package supports both ESM and CJS, but the default import is for the main object.
Model
✓ import { Model } from 'classy-mongo'
✗ const Model = require('classy-mongo').Model
Named export; available in both ESM and CJS.
connect
✓ import { connect } from 'classy-mongo'
✗ import connect from 'classy-mongo'
`connect` is a named export, not a default one.

Defines a Book model class with typed properties, inserts a document, retrieves it by ID, and accesses a computed property.

import { connect, Model } from 'classy-mongo'; await connect('mongodb://localhost:27017/mydb'); class Book extends Model { name = String.prototype; pages = [String.prototype]; isSpecial = Boolean.prototype; get pageCount() { return this.pages.length; } static getSpecials() { return this.find({ isSpecial: true }); } } const result = await Book.insertOne({ name: 'Test', pages: ['page1'] }); const book = await Book.findById(result.insertedId); console.log(book.pageCount);
Debug
Known issues
gotchaProperty types must be prototypes (e.g., String.prototype, Boolean.prototype), not constructors.
fix
Use String.prototype instead of String for default values.
affects: >=0.0.1
gotchaArray types must be wrapped in brackets with the prototype inside: [String.prototype].
fix
Define array fields as [String.prototype], not Arrays of plain strings.
affects: >=0.0.1
deprecatedThe `classy.connect()` method does not accept options (e.g., useNewUrlParser).
fix
Use `mongodb` driver directly for advanced connection options, or pass a connection string only.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: Class constructor Model cannot be invoked without 'new'
Using Model as a function instead of extending it as a class.
fix
Define a class that extends Model, e.g., class Book extends Model { ... }.
MongoError: cannot use 'prototype' property on non-object
Setting a field to a constructor like String instead of String.prototype.
fix
Use String.prototype for type definition.
Upgrade
Version history
0.0.14latest on npm
Audit
Dependencies
mongodbrequiredpeer dependency for MongoDB driver
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
classy-mongo — npm install classy-mongo · libregistry