{"id":25925,"library":"marpat","title":"Marpat","description":"Marpat is a lightweight ES6 class-based ODM (Object Document Mapper) for MongoDB and NeDB, forked from Camo. It provides a storage-agnostic document collection backend with schema validation via Joi since v3.0.0. Current stable version is 3.0.5, with a release cadence of several months. Supports hooks, embedded documents, counting, and custom database drivers. Key differentiators: ES6 class syntax, support for NeDB (file or in-memory) and MongoDB, integrated Joi validation, and a client registry for custom backends. Requires Node >=8.","status":"active","version":"3.0.5","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/luidog/marpat","tags":["javascript","es6","odm","mongodb","nedb","nosql","document","model","schema"],"install":[{"cmd":"npm install marpat","lang":"bash","label":"npm"},{"cmd":"yarn add marpat","lang":"bash","label":"yarn"},{"cmd":"pnpm add marpat","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required if using NeDB as the database backend","package":"nedb","optional":true},{"reason":"Required if using MongoDB as the database backend","package":"mongodb","optional":true}],"imports":[{"note":"Marpat is CJS-only; ESM imports may cause errors. Use require().","wrong":"import { Document } from 'marpat';","symbol":"Document","correct":"const { Document } = require('marpat');"},{"note":"Named export via destructuring is the standard pattern.","wrong":"const connect = require('marpat').connect;","symbol":"connect","correct":"const { connect } = require('marpat');"},{"note":"Same as Document, use destructuring.","wrong":"const EmbeddedDocument = require('marpat').EmbeddedDocument;","symbol":"EmbeddedDocument","correct":"const { EmbeddedDocument } = require('marpat');"}],"quickstart":{"code":"const { connect, Document } = require('marpat');\n\nclass Animal extends Document {\n  constructor() {\n    super();\n    this.name = String;\n    this.species = String;\n    this.age = { type: Number, default: 0 };\n  }\n}\n\nasync function main() {\n  const database = await connect('nedb://memory');\n  const cat = Animal.create({ name: 'Fluffy', species: 'Cat' });\n  await cat.save();\n  console.log('Saved cat:', cat);\n  const found = await Animal.findOne({ name: 'Fluffy' });\n  console.log('Found cat:', found);\n  await database.close();\n}\n\nmain().catch(console.error);","lang":"javascript","description":"Demonstrates connecting to an in-memory NeDB database, defining a model class extending Document, creating and saving a document, and finding it back."},"warnings":[{"fix":"Ensure your schema properties comply with Joi validation rules. See migration docs.","message":"In version 3.0.0, Joi schema validation was added. Existing schemas may need updating to avoid validation errors.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Remove any reliance on snyk being part of marpat's dependencies.","message":"The 'snyk' package was removed as a production dependency in v3.0.5; it was previously used for vulnerability scanning but is no longer bundled.","severity":"deprecated","affected_versions":"<3.0.5"},{"fix":"Use const { Document } = require('marpat'); instead of import.","message":"Marpat does not support ESM imports (import syntax). Use CommonJS require.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Assign the returned database to a variable or use it within the async scope.","message":"The 'connect()' function returns a database instance, but it does not automatically set a global database; you must pass the instance or rely on the returned promise.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use const { Document } = require('marpat');","cause":"Incorrect import: using default import instead of destructured require.","error":"TypeError: marpat.Document is not a constructor"},{"fix":"Run npm install nedb --save","cause":"NeDB not installed while using nedb:// URI.","error":"Error: Cannot find module 'nedb'"},{"fix":"Ensure property values match the declared type (e.g., Number, String).","cause":"Schema with Joi validation but property value is wrong type.","error":"ValidationError: \"age\" must be a number"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}