Lightweight ODM — No Database Required

mongoose-lite-js

A Mongoose-like ODM built in TypeScript with YAML storage.
Familiar API. Zero infrastructure. Instant setup.

Get Started
npm install mongoose-lite-js
TypeScript
Lightweight
Schema Validated
YAML Storage
app.js
import mongooseLite from "mongoose-lite-js";

mongooseLite.connect("./data");

const UserSchema = mongooseLite.Schema({
  username: { type: String, required: true },
  isActive: { type: Boolean, default: true },
  role:     { type: String, enum: ["tester", "dev"] },
});

const User = mongooseLite.model("User", UserSchema);

await User.create({ username: "Alex", role: "tester" });
const users = await User.find({});
console.log(users);

Everything you need,
nothing you don't.

Familiar Mongoose patterns without the infrastructure overhead. Build prototypes, CLI tools, and lightweight apps with confidence.

Document Creation

Create documents with create() and save() — just like Mongoose.

create() save()

Powerful Queries

Find documents with flexible filtering, single lookups, and ID-based retrieval.

find() findOne() findById()

Flexible Updates

Update single or multiple documents with a rich set of update operations.

updateOne() updateMany() findByIdAndUpdate() findOneAndUpdate() replaceOne()

Deletion

Remove documents by filter, ID, or the first match — clean and predictable.

deleteOne() deleteMany() findByIdAndDelete() findOneAndDelete()

Utilities

Count documents and check existence without loading full records.

countDocuments() exists()

Schema Validation

Define structure, required fields, enums, min/max, defaults and more — all enforced.

required enum default min/max

Data flow,
visualized.

From your application code to YAML persistence — every step is clear, validated, and predictable.

Application Code

Your JS/TS application imports and uses the library

Entry Point

connect()

Initialize storage directory

mongooseLite.connect("./data")
Connection

Schema()

Define structure & validation rules

type, required, enum, default
Definition

model()

Create model bound to collection

mongooseLite.model("User", schema)
Binding

CRUD Operations

Perform create, read, update, delete through the Model API

Create Read Update Delete

Validation Layer

Schema rules enforced before persistence

Type checking Required fields Enum values Min / Max

Utility Layer

Defaults applied, updates processed, filters matched

applyDefaults applyUpdates matchFilter

YAML File Storage

Persisted as human-readable .yaml files via js-yaml

user.yaml
product.yaml
order.yaml

Up and running in
under a minute.

Install the package, connect to a directory, define your schema, and start querying.

01

Install

Terminal
npm install mongoose-lite-js
02

Connect

app.js
import mongooseLite from "mongoose-lite-js";

mongooseLite.connect("./data");

Data is persisted as YAML files inside the connected directory.

03

Define Schema

app.js
const UserSchema = mongooseLite.Schema({
  username:   { type: String,  required: true },
  isActive:   { type: Boolean, default: true },
  role:       { type: String,  enum: ["tester", "developer"] },
  experience: Number
});
04

Use the Model

app.js
const User = mongooseLite.model("User", UserSchema);

await User.create({ username: "Alex", role: "tester" });

const users = await User.find({});
console.log(users);

CommonJS Support

You can also use CommonJS import syntax:

const mongooseLite = require("mongoose-lite-js");

Structured, validated,
type-safe data.

Define your data shape with powerful constraints — the same patterns you already know from Mongoose.

Capabilities

  • Primitive types — String, Number, Boolean, Date
  • Complex types — Array, Object
  • Required — Enforce field presence
  • Defaults — Static or function-based
  • Enum — Restrict to allowed values
  • Min / Max — Numeric constraints
  • Min / Max Length — String constraints
  • Nested Objects — Deep structure support
  • Typed Arrays — Arrays of specific types

Example

ProductSchema.ts
const ProductSchema = mongooseLite.Schema({
  name:  { type: String,  required: true },
  price: { type: Number,  min: 0 },
  tags:  [String],
  details: {
    weight:       Number,
    manufacturer: String
  }
});

Complete API at
a glance.

All the methods you'd expect from Mongoose — battle-tested patterns, zero configuration.

Create

Model.create(doc)

Create and persist a new document

doc.save()

Save the document instance to storage

Query

Model.find(filter)

Find all matching documents

Model.findOne(filter)

Find the first matching document

Model.findById(id)

Find a document by its ID

Update

Model.updateOne(filter, update)

Update the first matching document

Model.updateMany(filter, update)

Update all matching documents

Model.findByIdAndUpdate(id, update)

Find by ID and apply updates

Model.findOneAndUpdate(filter, update)

Find first match and update

Model.replaceOne(filter, doc)

Replace the first matching document entirely

Delete

Model.deleteOne(filter)

Delete the first matching document

Model.deleteMany(filter)

Delete all matching documents

Model.findByIdAndDelete(id)

Find by ID and delete

Model.findByIdAndRemove(id)

Alias for findByIdAndDelete

Model.findOneAndDelete(filter)

Find first match and delete

Model.findOneAndRemove(filter)

Alias for findOneAndDelete

Utilities

Model.countDocuments(filter)

Return count of matching documents

Model.exists(filter)

Check if any document matches

Core

mongooseLite.Schema(definition)

Define structure, validation rules, and defaults

mongooseLite.model(name, schema)

Create a model bound to a YAML collection

mongooseLite.connect(path)

Initialize YAML-based storage at the given path

project-root/
data/
user.yaml
product.yaml

YAML-Based Storage

Data is persisted as human-readable YAML files inside the directory you pass to connect(). Each model maps to a single .yaml file — no external database needed.

Dependency: js-yaml — for reading and writing YAML files

Clean architecture,
well organized.

The source code is split into focused modules — easy to understand, extend, and contribute to.

src/
core/
Schema.ts Schema definition & validation rules
Model.ts Model class with CRUD operations
index.ts Core module exports
types/
common.types.ts Shared type definitions
Types.ts Core type exports
db/
Connection.ts Storage connection manager
DBHelper.ts Low-level DB operations
utils/
applyDefaults.ts Apply default values to documents
applyUpdates.ts Apply update operations
matchFilter.ts Query filter matching logic
yamlHelper.ts YAML read/write utilities
errors/
ValidationError.ts Custom validation error class
index.ts Library entry point

Limitations

  • Not intended for high-concurrency or large-scale production systems
  • File-based storage may not be suitable for large datasets
  • No built-in indexing or advanced query optimization