npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

simple-light-mongo-orm

v1.0.5

Published

A lightweight JavaScript ORM for MongoDB

Readme

Simple-Light Mongo ORM

A minimal JavaScript ORM for MongoDB, designed to provide a clean and easy interface for working with Mongo collections as JavaScript objects — without the overhead of frameworks like Mongoose.


Features

  • Schema-based validation (type, required, default, custom validators)
  • Simple CRUD API: create, find, findOne, updateOne, deleteOne
  • Lifecycle hooks: preSave, postSave
  • Basic populate helper (resolve references between models)
  • Works directly with official MongoDB Node.js driver
  • Lightweight (no dependencies other than mongodb)

Installation

npm install simple-light-mongo-orm

Or add it manually to your package.json:

"dependencies": {
  "simple-light-mongo-orm": "^1.0.0"
}

Quick Start Example

const { connect, model, Schema, disconnect } = require('simple-light-mongo-orm')

async function main() {
  // Connect to MongoDB
  await connect('mongodb://127.0.0.1:27017', 'testdb')

  // Define a schema
  const User = await model('users', new Schema({
    name: { type: 'String', required: true },
    email: { type: 'String', required: true, validate: v => v.includes('@') },
    age: { type: 'Number', default: 18 }
  }))

  // Create a new user
  const user = await User.create({ name: 'Alice', email: '[email protected]' })
  console.log('Created user:', user)

  // Query users
  const found = await User.findOne({ name: 'Alice' })
  console.log('Found user:', found)

  // Disconnect
  await disconnect()
}

main().catch(console.error)

Define Models

const Post = await model('posts', new Schema({
  title: { type: 'String', required: true },
  body: 'String',
  author: { type: 'ObjectId', required: true }
}))

Populate Example

You can populate references between models easily:

const posts = await Post.find({})
await Post.populate(posts, [{ path: 'author', model: User }])
console.log(posts)

Hooks

Hooks allow you to execute functions before or after saving a document.

User.on('preSave', (doc) => {
  doc.createdAt = new Date()
})

User.on('postSave', (doc) => {
  console.log(`User saved: ${doc.name}`)
})

Validation

Schemas automatically validate types, required fields, and custom rules.

const Product = await model('products', new Schema({
  name: { type: 'String', required: true },
  price: { type: 'Number', validate: v => v > 0 }
}))

API Summary

connect(uri, dbName)

Connect to your MongoDB database.

model(name, schema)

Create or get a model (collection).

Schema(definition)

Define your schema with types, defaults, and validators.

Model.create(data)

Insert a new document.

Model.find(query)

Find multiple documents.

Model.findOne(query)

Find a single document.

Model.updateOne(query, update)

Update a document and return the updated result.

Model.deleteOne(query)

Delete a single document.

Document.save()

Save an existing or new document instance.

Document.remove()

Delete a document instance.


License

MIT License © 2025 — Created by izmroen


Contribute

Contributions are welcome! If you have ideas for improvements (relations, migrations, query builder, etc.), feel free to open an issue or pull request.


Keywords

mongo · mongodb · orm · odm · lightweight · database · javascript · nodejs