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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mongodb-web-beast

v1.0.0

Published

MongoDB Web Beast - Modern MongoDB ORM for Node.js with chainable API, validation, and relationships.

Downloads

1

Readme

MongoDB Web Beast

Made with ❤️ by Web Beast npm version License: MIT

A modern MongoDB ORM for Node.js with chainable API, validation, and relationships. Built on top of Mongoose for robust MongoDB operations.

Built with ❤️ by Web Beast - Your Ultimate Web Development Resource

Features

Modern API - Familiar methods like User.paginate(10), User.create({...})
Chainable Queries - where(), orWhere(), whereHas(), orderBy(), select()
Developer Experience - Type-safe with TypeScript, intuitive API, works with JavaScript and TypeScript
Built with Mongoose - Robust MongoDB ODM
Validation - Simple, expressive validation rules
Relationships - Easy relationship handling with with() and whereHas()
Pagination - Built-in pagination with metadata

Installation

npm install mongodb-web-beast mongoose

Quick Start

import mongoose from 'mongoose'
import { Model } from 'mongodb-web-beast'

// Define your schema
const userSchema = new mongoose.Schema({
  name: { type: String, required: true },
  email: { type: String, required: true, unique: true },
  status: { type: String, enum: ['active', 'inactive'], default: 'active' }
})

// Create your model
export class User extends Model {}
User.init(userSchema)

// Use modern methods
const users = await User.paginate(10)
const newUser = await User.create({ name: 'John', email: '[email protected]' })
const activeUsers = await User.where('status', 'active').get()

Basic Usage

Creating Records

// Create a single record
const user = await User.create({
  name: 'Brij Patel',
  email: '[email protected]',
  status: 'active'
})

// Create multiple records
const users = await User.createMany([
  { name: 'John', email: '[email protected]' },
  { name: 'Jane', email: '[email protected]' }
])

Finding Records

// Find by ID
const user = await User.find('507f1f77bcf86cd799439011')

// Find by ID or throw error
const user = await User.findOrFail('507f1f77bcf86cd799439011')

// Get first record
const firstUser = await User.first()

// Get first record or throw error
const firstUser = await User.firstOrFail()

// Get all records
const allUsers = await User.all()

Query Builder

// Basic where clause
const activeUsers = await User.where('status', 'active').get()

// Multiple conditions
const users = await User
  .where('status', 'active')
  .where('age')
  .gte(25)
  .lte(40)
  .get()

// OR conditions
const users = await User
  .where('status', 'active')
  .orWhere('status', 'pending')
  .get()

// IN conditions
const users = await User.whereIn('status', ['active', 'pending']).get()

// LIKE search
const users = await User.whereLike('email', '@gmail.com').get()

// NULL checks
const users = await User.whereNull('deletedAt').get()
const users = await User.whereNotNull('email').get()

Ordering and Selecting

// Order by field
const users = await User.orderBy('name', 'asc').get()
const users = await User.orderBy('createdAt', 'desc').get()

// Select specific fields
const users = await User.select('name email').get()
const users = await User.select(['name', 'email', 'status']).get()

Pagination

// Basic pagination
const result = await User.paginate(10, 1)

console.log(result.data) // Array of users
console.log(result.pagination)
// {
//   current_page: 1,
//   per_page: 10,
//   total: 100,
//   total_pages: 10,
//   has_next_page: true,
//   has_prev_page: false
// }

// With query conditions
const result = await User
  .where('status', 'active')
  .orderBy('createdAt', 'desc')
  .paginate(20, 2)

Relationships

// Include relationships
const posts = await Post.with('author').get()

// Multiple relationships
const posts = await Post.with(['author', 'comments']).get()

// Where has relationship
const users = await User
  .whereHas('posts', q => q.where('published', true))
  .get()

// Where doesn't have relationship
const users = await User
  .whereDoesntHave('posts')
  .get()

Validation

// Define validation rules
const rules = {
  name: { required: true, min: 2, max: 50 },
  email: { required: true, email: true },
  age: { min: 0, max: 150 },
  password: { 
    required: true, 
    min: 8,
    custom: (value) => {
      // Custom validation
      if (!/[A-Z]/.test(value)) {
        return 'Password must contain at least one uppercase letter'
      }
      return true
    }
  }
}

// Validate data
const data = {
  name: 'John',
  email: '[email protected]',
  age: 25,
  password: 'weak'
}

const result = await User.validate(data, rules)
if (!result.isValid) {
  console.log(result.errors)
}

Advanced Queries

// Complex query with multiple conditions
const users = await User
  .where('status', 'active')
  .where('age')
  .gte(25)
  .lte(40)
  .whereLike('email', '@example.com')
  .orderBy('age', 'asc')
  .select('name email age')
  .limit(10)
  .get()

// Count queries
const totalUsers = await User.count()
const activeUsersCount = await User.where('status', 'active').count()

// Exists check
const hasActiveUsers = await User.where('status', 'active').exists()

Updates and Deletes

// Update by ID
const updatedUser = await User.update(userId, { status: 'inactive' })

// Update or create
const user = await User.updateOrCreate(
  { email: '[email protected]' },
  { name: 'John Doe', status: 'active' }
)

// Delete by ID
const deleted = await User.delete(userId)

// Delete multiple
const deletedCount = await User.deleteMany({ status: 'inactive' })

Model Definition

import { Schema } from 'mongoose'
import { Model } from 'mongodb-web-beast'

const userSchema = new Schema({
  name: {
    type: String,
    required: true,
    trim: true
  },
  email: {
    type: String,
    required: true,
    unique: true,
    lowercase: true
  },
  status: {
    type: String,
    enum: ['active', 'inactive', 'pending'],
    default: 'pending'
  },
  age: {
    type: Number,
    min: 0,
    max: 150
  }
}, {
  timestamps: true
})

// Add indexes
userSchema.index({ email: 1 })
userSchema.index({ status: 1 })

export class User extends Model {
  // Custom static methods
  static async findActiveUsers() {
    return this.where('status', 'active').get()
  }

  static async findUsersByAgeRange(minAge: number, maxAge: number) {
    return this.where('age')
      .gte(minAge)
      .lte(maxAge)
      .orderBy('age', 'asc')
      .get()
  }

  // Validation rules
  static getValidationRules() {
    return {
      name: { required: true, min: 2, max: 50 },
      email: { required: true, email: true },
      status: { required: true },
      age: { min: 0, max: 150 }
    }
  }
}

// Initialize the model
User.init(userSchema, 'users')

API Reference

Static Methods

CRUD Operations

  • create(data) - Create a new record
  • createMany(dataArray) - Create multiple records
  • find(id) - Find record by ID
  • findOrFail(id) - Find record by ID or throw error
  • first() - Get first record
  • firstOrFail() - Get first record or throw error
  • all() - Get all records
  • update(id, data) - Update record by ID
  • updateOrCreate(criteria, data) - Update or create record
  • delete(id) - Delete record by ID
  • deleteMany(criteria) - Delete multiple records

Query Builders

  • where(field, value) - Add where clause
  • orWhere(field, value) - Add OR where clause
  • whereIn(field, values) - Add IN where clause
  • whereNotIn(field, values) - Add NOT IN where clause
  • whereNull(field) - Add NULL where clause
  • whereNotNull(field) - Add NOT NULL where clause
  • whereLike(field, value) - Add LIKE where clause
  • whereHas(relation, callback?) - Add relationship where clause
  • whereDoesntHave(relation, callback?) - Add relationship not exists clause
  • paginate(perPage, page) - Get paginated results
  • count() - Count records
  • exists() - Check if records exist

Validation

  • validate(data, rules) - Validate data against rules

QueryBuilder Methods

Conditions

  • where(field, value) - Add where clause
  • orWhere(field, value) - Add OR where clause
  • whereOperator(field, operator, value) - Add custom operator
  • whereIn(field, values) - Add IN where clause
  • whereNotIn(field, values) - Add NOT IN where clause
  • whereNull(field) - Add NULL where clause
  • whereNotNull(field) - Add NOT NULL where clause
  • whereLike(field, value) - Add LIKE where clause
  • whereHas(relation, callback?) - Add relationship where clause
  • whereDoesntHave(relation, callback?) - Add relationship not exists clause

Modifiers

  • orderBy(field, direction) - Order results
  • select(fields) - Select specific fields
  • with(relations) - Include relationships
  • limit(limit) - Limit results
  • skip(skip) - Skip results

Execution

  • get() - Get all results
  • first() - Get first result
  • firstOrFail() - Get first result or throw error
  • paginate(perPage, page) - Get paginated results
  • count() - Count results
  • exists() - Check if results exist

Validation Rules

interface ValidationRule {
  required?: boolean
  email?: boolean
  min?: number
  max?: number
  unique?: boolean
  custom?: (value: any) => boolean | string
}

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Inspired by modern Node.js and JavaScript ORM patterns
  • Built on top of Mongoose
  • Designed for developer experience and productivity

🚀 More from Web Beast

MongoDB Web Beast is proudly created by Web Beast - Your Ultimate Web Development Resource.

🔗 Connect With Us

  • 🌐 Website: web-beast.com
  • 📧 Contact: Get in touch for custom development solutions
  • 💡 Resources: Free templates, tutorials, and development guides
  • 📦 GitHub: mongodb-web-beast

🛠️ Our Services

  • Web Development: Full-stack solutions with modern technologies
  • Node.js Development: Expert Node.js applications and APIs
  • React & Vue.js: Frontend development with modern frameworks
  • MongoDB Solutions: Database design and optimization
  • UI/UX Design: Beautiful and functional user interfaces

📚 Popular Resources