Registry / database / p-odm
library3.1.18jsnpmunverified

Minimalistic ODM (Object Document Mapper) for MongoDB on Node.js. Version 3.1.18 wraps the node-mongodb-native driver with a simple model API including find, save, and remove operations. Requires Node >=0.4.12. It is a lightweight alternative to Mongoose with a focus on simplicity, error handling via callbacks, and common idioms. Designed for small projects or when a full-featured ODM is unnecessary.

npm install p-odm
INSTALL
IMPORT
SIG · P-ODM
P
p-odm
databasejavascriptv3.1.18
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.

ODM
✓ var ODM = require('odm')
✗ import ODM from 'odm'
The package is CommonJS-only and does not support ESM imports. The npm package name is 'odm', not 'p-odm'.
model
✓ var User = ODM.model('users', {name: String, Birthday: Date})
✗ var User = new ODM.model('users', {name: String, Birthday: Date})
ODM.model() returns a Model constructor; do not use 'new' on the return value.
connect
✓ ODM.connect('mongodb://localhost/test')
✗ ODM.connect('localhost:27017/test')
The connection string must include the protocol (mongodb://). The library does not support connection options like authSource; use the native driver directly if needed.

Connects to MongoDB, defines a User model with name and Birthday fields, fetches all users, creates and saves a new user.

var ODM = require('odm'); ODM.connect('mongodb://localhost/test'); var User = ODM.model('users', {name: String, Birthday: Date}); User.findAll(function(err, users) { if (err) { console.log('Error:', err); return; } for (var i = 0; i < users.length; i++) { console.log(users[i]); } }); var user = new User({name: 'Alice', Birthday: new Date('1990-01-01')}); user.save(function(err) { if (err) throw err; console.log('User saved'); });
Debug
Known issues
gotchaThe npm package name is 'odm', not 'p-odm'. Attempting to install 'p-odm' will fail.
fix
Install with 'npm install odm' (case-insensitive) and require with 'require('odm')'.
affects: >=0.0.0
deprecatedThe library uses callbacks only and does not support Promises or async/await. This is a deprecated pattern for modern Node.js applications.
fix
Wrap callbacks in a Promise or use an alternative ODM that supports Promises, such as Mongoose or the native MongoDB driver.
affects: >=0.0.0
gotchaODM.connect() does not accept options like auth, dbName, or replicaSet. It only takes a connection string.
fix
Use the native MongoDB driver directly if advanced connection options are required.
affects: >=0.0.0
gotchaThe model definition does not support nested schemas, validation, or middleware. It only accepts flat objects with key-type pairs.
fix
For complex schemas, consider using Mongoose or validate data manually before saving.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: ODM.connect is not a function
Forgetting to require('odm') or requiring the wrong package name.
fix
Ensure 'var ODM = require('odm');' is executed before calling ODM.connect().
Cannot find module 'odm'
Package 'odm' not installed; it may be confused with the GitHub repo name 'p-odm'.
fix
Run 'npm install odm' (not 'npm install p-odm').
TypeError: Object #<Object> has no method 'findAll'
Attempting to call findAll on a model instance instead of the Model constructor.
fix
Use 'User.findAll(callback)' where User is the model returned from ODM.model(), not a new User instance.
Upgrade
Version history
3.1.18latest on npm
Audit
Dependencies
mongodbrequiredThe core MongoDB driver that p-odm wraps. Required at runtime for database operations.
Agent activity
7 hits · last 30 days
node
6
Resources
packagep-odm ↗
p-odm — npm install p-odm · libregistry