Registry / database / mongoorm

mongoorm

JSON →
library0.0.21jsnpmunverified

MongoORM is an Object-Document Mapper for MongoDB in Node.js, designed to simplify CRUD operations and schema management. As of version 0.0.21, it's an early-stage library with a class-based approach extending a Document prototype. It provides a declarative schema definition using field types like String and integrates directly with the MongoDB Node.js driver. Compared to Mongoose, it's lighter and more minimal, but lacks maturity and community adoption. Release cadence is irregular; updates are infrequent.

npm install mongoorm
INSTALL
IMPORT
SIG · MONGOORM
M
mongoorm
databasejavascriptv0.0.21
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.

MongoORM
import MongoORM from 'mongoorm'
const { MongoORM } = require('mongoorm')
Default import; named import will result in undefined.
Document
import { Document } from 'mongoorm'
const Document = require('mongoorm').Document
CommonJS destructuring works, but ESM named import is preferred.
fields
import { Document } from 'mongoorm'; class User extends Document { initFields(fields) { ... } }
const { Document } = require('mongoorm'); class User extends Document { initFields() { ... } }
Fields parameter is passed to initFields; not using it will break schema definition.

Demonstrates connecting to MongoDB, defining a schema, creating a document, and saving it.

import MongoORM, { Document } from 'mongoorm'; await MongoORM.connect('mongodb://localhost:27017/mydb', {}); class User extends Document { initFields(fields) { return { firstName: fields.String(), lastName: fields.String(), email: fields.String(), }; } } const user = new User({ document: 'users' }); const doc = user.create({ firstName: 'John', lastName: 'Doe', email: 'john@example.com' }); await doc.save(); console.log('User saved:', doc);
Debug
Known issues
breakingThe 'create' method returns a plain object, not a Document instance in older versions
fix
Upgrade to >=0.0.15 or always call doc.save() on the result of create.
affects: <0.0.15
deprecatedUsing connect() as a static method without await may cause race conditions
fix
Always await the connect() call before performing operations.
affects: >=0.0.1
gotchaField names must match exactly; nested objects require explicit schema
fix
Define nested fields as shown in README: address: { city: fields.String(), pin: fields.String() }
affects: >=0.0.1
gotchaDocument instances must be created with new, but the new keyword is not used; use new User() or create()
fix
Use const user = new User({ document: 'collectionName' });
affects: >=0.0.1
gotchaConnection must be established before any schema or document operations
fix
Wrap all operations in an async function that awaits connect.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'String')
Calling fields.String() before connection or importing incorrectly
fix
Ensure MongoORM.connect() has been called and import { Document } from 'mongoorm'.
MongoError: not authorized on admin to execute command
Connection string lacks proper authentication or user permissions
fix
Use connection string format: mongodb://user:pass@host:port/db
TypeError: doc.save is not a function
The object returned from create() is not a Document instance in older versions
fix
Upgrade mongoorm to >=0.0.15 or use new User() and assign fields manually.
MongoError: cannot infer collection name from schema
Missing 'document' option when instantiating Document subclass
fix
Add { document: 'collectionName' } to constructor: new User({ document: 'users' })
Upgrade
Version history
0.0.21latest on npm
Audit
Dependencies
mongodbrequiredRequired for connecting and interacting with MongoDB
Agent activity
5 hits · last 30 days
node
4
Resources
mongoorm — npm install mongoorm · libregistry