Registry / database / w-orm-mongodb

w-orm-mongodb

JSON →
library1.1.33jsnpmunverified

An operator for MongoDB in Node.js, providing a simple ORM-like interface for basic CRUD operations (insert, select, save, delete) with support for MongoDB operators like $and, $or, $gt, $lt, $regex, and more. Current stable version is 1.1.33. The package uses an event-driven change monitoring system and offers both ESM and UMD module formats. It is lightweight and minimal compared to full-featured ORMs like Mongoose, focusing on ease of use for small to medium projects. However, it lacks TypeScript support and comprehensive documentation, and the API uses callbacks/promises with minimal error handling.

npm install w-orm-mongodb
INSTALL
IMPORT
SIG · W-ORM-MONGODB
W
w-orm-mongodb
databasejavascriptv1.1.33
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.

WOrm
import WOrm from 'w-orm-mongodb'
const { WOrm } = require('w-orm-mongodb')
Library uses default export only. Named exports do not exist.
WOrm
const WOrm = require('w-orm-mongodb')
For CommonJS environments, require returns the default export directly.
WOrm instance methods
const orm = WOrm({ url: '...', db: '...', cl: '...' }) orm.on('change', callback) orm.insert(data).then(...) orm.select(query).then(...) orm.save(data, options).then(...) orm.del(data).then(...) orm.delAll().then(...)
WOrm.insert(data) instead of using an instance
WOrm() returns an instance; methods are not static. Always create an instance first.

Shows basic CRUD operations: insert, select with operators, save (update), and delete.

import WOrm from 'w-orm-mongodb' const opt = { url: process.env.MONGO_URL ?? 'mongodb://localhost:27017', db: 'test', cl: 'users' } async function main() { const wo = WOrm(opt) // Insert multiple documents await wo.insert([ { name: 'Alice', age: 30 }, { name: 'Bob', age: 25 } ]) // Select all const all = await wo.select() console.log('All docs:', all) // Query with $gt const adults = await wo.select({ age: { '$gt': 20 } }) console.log('Adults:', adults) // Update (save with upsert) await wo.save( [{ name: 'Alice', age: 31 }], { autoInsert: false } ) // Delete one const toDelete = await wo.select({ name: 'Bob' }) await wo.del(toDelete) } main().catch(console.error)
Debug
Known issues
gotchaThe `select` method returns an array of matched documents. An empty query `{}` returns all documents.
fix
Always handle the result as an array, even for single-document queries.
affects: >=1.0.0
gotchaThe `save` method with `autoInsert: false` only updates existing documents (matched by `id` field). It will not insert new ones.
fix
Set `autoInsert: true` to enable upsert behavior, or use `insert` for new documents.
affects: >=1.0.0
deprecatedThe library uses callback-style event listeners (e.g., `wo.on('change', callback)`). This pattern is deprecated in favor of promises or async iterators.
fix
Consider wrapping event listeners in promises or using async/await with the method results directly.
affects: >=1.0.0
gotchaThe `WOrm` function expects a config object with `url`, `db`, and `cl`. If `cl` (collection) is missing, the library will silently fail or use an undefined collection.
fix
Always include all three required fields in the config object.
affects: >=1.0.0
breakingIn version 1.1.x, the import path changed from 'w-orm-mongodb/dist/w-orm-mongodb.umd.js' to 'w-orm-mongodb' for ESM.
fix
Use `import WOrm from 'w-orm-mongodb'` instead of the old UMD path.
affects: >=1.1.0
Errors
Common errors & fixes
TypeError: WOrm is not a function
Importing the library incorrectly, e.g., using named import instead of default import.
fix
Use `import WOrm from 'w-orm-mongodb'` (ESM) or `const WOrm = require('w-orm-mongodb')` (CJS).
Cannot read properties of undefined (reading 'insert')
Calling a method on the result of `WOrm(opt)` without waiting for the instance to be ready, or forgetting to call `WOrm(opt)` first.
fix
Store the instance: `const wo = WOrm(opt)`, then call `await wo.insert(...)`.
MongoError: Authentication failed
Invalid MongoDB URL credentials or permissions.
fix
Ensure the URL format is correct: `mongodb://username:password@host:port` and the user has access to the specified database.
wo.on is not a function
Trying to use the event API on a wrong object (e.g., on the class itself instead of an instance).
fix
Create an instance first: `const wo = WOrm(opt)` then call `wo.on(...)`.
Upgrade
Version history
1.1.33latest on npm
Audit
Dependencies
mongodbrequiredCore MongoDB driver for database operations.
w-jsonoptionalUsed for JSON manipulation and validation.
w-fsoptionalFile system utilities for potential caching or config.
Agent activity
18 hits · last 30 days
node
14
Meta
1
OpenAI (training)
1
Resources
w-orm-mongodb — npm install w-orm-mongodb · libregistry