Registry / database / marpat

marpat

JSON →
library3.0.5jsnpmunverified

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.

npm install marpat
INSTALL
IMPORT
SIG · MARPAT
M
marpat
databasejavascriptv3.0.5
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.

Document
const { Document } = require('marpat');
import { Document } from 'marpat';
Marpat is CJS-only; ESM imports may cause errors. Use require().
connect
const { connect } = require('marpat');
const connect = require('marpat').connect;
Named export via destructuring is the standard pattern.
EmbeddedDocument
const { EmbeddedDocument } = require('marpat');
const EmbeddedDocument = require('marpat').EmbeddedDocument;
Same as Document, use destructuring.

Demonstrates connecting to an in-memory NeDB database, defining a model class extending Document, creating and saving a document, and finding it back.

const { connect, Document } = require('marpat'); class Animal extends Document { constructor() { super(); this.name = String; this.species = String; this.age = { type: Number, default: 0 }; } } async function main() { const database = await connect('nedb://memory'); const cat = Animal.create({ name: 'Fluffy', species: 'Cat' }); await cat.save(); console.log('Saved cat:', cat); const found = await Animal.findOne({ name: 'Fluffy' }); console.log('Found cat:', found); await database.close(); } main().catch(console.error);
Debug
Known issues
breakingIn version 3.0.0, Joi schema validation was added. Existing schemas may need updating to avoid validation errors.
fix
Ensure your schema properties comply with Joi validation rules. See migration docs.
affects: >=3.0.0 <4.0.0
deprecatedThe 'snyk' package was removed as a production dependency in v3.0.5; it was previously used for vulnerability scanning but is no longer bundled.
fix
Remove any reliance on snyk being part of marpat's dependencies.
affects: <3.0.5
gotchaMarpat does not support ESM imports (import syntax). Use CommonJS require.
fix
Use const { Document } = require('marpat'); instead of import.
affects: >=1.0.0
gotchaThe '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.
fix
Assign the returned database to a variable or use it within the async scope.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: marpat.Document is not a constructor
Incorrect import: using default import instead of destructured require.
fix
Use const { Document } = require('marpat');
Error: Cannot find module 'nedb'
NeDB not installed while using nedb:// URI.
fix
Run npm install nedb --save
ValidationError: "age" must be a number
Schema with Joi validation but property value is wrong type.
fix
Ensure property values match the declared type (e.g., Number, String).
Upgrade
Version history
3.0.5latest on npm
Audit
Dependencies
nedboptionalRequired if using NeDB as the database backend
mongodboptionalRequired if using MongoDB as the database backend
Agent activity
2 hits · last 30 days
node
2
Resources
marpat — npm install marpat · libregistry