{"id":45717,"library":"p-odm","title":"p-odm","description":"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.","status":"maintenance","version":"3.1.18","language":"javascript","source_language":"en","source_url":"https://github.com/pmlopes/p-odm","tags":["javascript","mongodb","database","mongo","model","view"],"install":[{"cmd":"npm install p-odm","lang":"bash","label":"npm"},{"cmd":"yarn add p-odm","lang":"bash","label":"yarn"},{"cmd":"pnpm add p-odm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The core MongoDB driver that p-odm wraps. Required at runtime for database operations.","package":"mongodb","optional":false}],"imports":[{"note":"The package is CommonJS-only and does not support ESM imports. The npm package name is 'odm', not 'p-odm'.","wrong":"import ODM from 'odm'","symbol":"ODM","correct":"var ODM = require('odm')"},{"note":"ODM.model() returns a Model constructor; do not use 'new' on the return value.","wrong":"var User = new ODM.model('users', {name: String, Birthday: Date})","symbol":"model","correct":"var User = ODM.model('users', {name: String, Birthday: Date})"},{"note":"The connection string must include the protocol (mongodb://). The library does not support connection options like authSource; use the native driver directly if needed.","wrong":"ODM.connect('localhost:27017/test')","symbol":"connect","correct":"ODM.connect('mongodb://localhost/test')"}],"quickstart":{"code":"var ODM = require('odm');\nODM.connect('mongodb://localhost/test');\n\nvar User = ODM.model('users', {name: String, Birthday: Date});\n\nUser.findAll(function(err, users) {\n  if (err) {\n    console.log('Error:', err);\n    return;\n  }\n  for (var i = 0; i < users.length; i++) {\n    console.log(users[i]);\n  }\n});\n\nvar user = new User({name: 'Alice', Birthday: new Date('1990-01-01')});\nuser.save(function(err) {\n  if (err) throw err;\n  console.log('User saved');\n});","lang":"javascript","description":"Connects to MongoDB, defines a User model with name and Birthday fields, fetches all users, creates and saves a new user."},"warnings":[{"fix":"Install with 'npm install odm' (case-insensitive) and require with 'require('odm')'.","message":"The npm package name is 'odm', not 'p-odm'. Attempting to install 'p-odm' will fail.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Wrap callbacks in a Promise or use an alternative ODM that supports Promises, such as Mongoose or the native MongoDB driver.","message":"The library uses callbacks only and does not support Promises or async/await. This is a deprecated pattern for modern Node.js applications.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Use the native MongoDB driver directly if advanced connection options are required.","message":"ODM.connect() does not accept options like auth, dbName, or replicaSet. It only takes a connection string.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"For complex schemas, consider using Mongoose or validate data manually before saving.","message":"The model definition does not support nested schemas, validation, or middleware. It only accepts flat objects with key-type pairs.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.4.12':35 '3.1.18':14 'altern':40 'api':26 'callback':51 'common':53 'databas':70 'design':55 'document':7 'driver':21 'error':48 'featur':64 'find':28 'focus':45 'full':63 'full-featur':62 'handl':49 'idiom':54 'includ':27 'javascript':68 'lightweight':39 'mapper':8 'minimalist':4 'model':25,72 'mongo':71 'mongodb':10,19,69 'mongoos':42 'nativ':20 'node':18,34 'node-mongodb-n':17 'node.js':12 'object':6 'odm':3,5,65 'oper':32 'p':2 'p-odm':1 'project':58 'remov':31 'requir':33 'save':29 'simpl':24 'simplic':47 'small':57 'unnecessari':67 'version':13 'via':50 'view':73 'wrap':15","created_at":"2026-06-07T12:56:22.971031+00:00","updated_at":"2026-06-07T12:56:22.971031+00:00","problems":[{"fix":"Ensure 'var ODM = require('odm');' is executed before calling ODM.connect().","cause":"Forgetting to require('odm') or requiring the wrong package name.","error":"TypeError: ODM.connect is not a function"},{"fix":"Run 'npm install odm' (not 'npm install p-odm').","cause":"Package 'odm' not installed; it may be confused with the GitHub repo name 'p-odm'.","error":"Cannot find module 'odm'"},{"fix":"Use 'User.findAll(callback)' where User is the model returned from ODM.model(), not a new User instance.","cause":"Attempting to call findAll on a model instance instead of the Model constructor.","error":"TypeError: Object #<Object> has no method 'findAll'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/pmlopes/p-odm","github":"https://github.com/pmlopes/p-odm","docs":null,"changelog":null,"pypi":null,"npm":"p-odm","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}