{"id":32475983,"url":"https://github.com/dashersw/memgoose","last_synced_at":"2025-10-26T21:27:57.862Z","repository":{"id":320088710,"uuid":"1073957277","full_name":"dashersw/memgoose","owner":"dashersw","description":"An in-memory mongoose impersonator","archived":false,"fork":false,"pushed_at":"2025-10-21T20:53:57.000Z","size":268,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-21T22:27:25.537Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dashersw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-10T22:29:01.000Z","updated_at":"2025-10-21T20:53:59.000Z","dependencies_parsed_at":"2025-10-21T22:27:30.269Z","dependency_job_id":"496bd8ef-2a3a-42bb-bd99-f3bf9e3375f4","html_url":"https://github.com/dashersw/memgoose","commit_stats":null,"previous_names":["dashersw/memgoose"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/dashersw/memgoose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashersw%2Fmemgoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashersw%2Fmemgoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashersw%2Fmemgoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashersw%2Fmemgoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashersw","download_url":"https://codeload.github.com/dashersw/memgoose/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashersw%2Fmemgoose/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281178681,"owners_count":26456676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-26T02:00:06.575Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-26T21:27:54.511Z","updated_at":"2025-10-26T21:27:57.851Z","avatar_url":"https://github.com/dashersw.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# memgoose\n\nA **lightweight, type-safe, in-memory database** with MongoDB-like API and pluggable persistence. Built for testing, caching, and rapid development with familiar Mongoose-style schemas.\n\n[![npm version](https://badge.fury.io/js/memgoose.svg)](https://badge.fury.io/js/memgoose)\n[![npm downloads](https://img.shields.io/npm/dm/memgoose.svg)](https://www.npmjs.com/package/memgoose)\n[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Tests](https://img.shields.io/badge/tests-800%2B%20passing-brightgreen.svg)]()\n\n## At a Glance\n\n```typescript\n// Define schema with validation, indexes, and hooks\nconst userSchema = new Schema({\n  email: { type: String, unique: true },\n  age: { type: Number, min: 0 }\n}, { timestamps: true })\n\nuserSchema.index('email') // O(1) lookups\n\n// Choose your storage\nconnect({ storage: 'memory' })           // Testing: 0 setup, fastest\nconnect({ storage: 'sqlite', ... })      // Production: ACID, persistent\nconnect({ storage: 'wiredtiger', ... })  // Enterprise: MongoDB-grade performance\n```\n\n| **Metric**        | **Value**                         |\n| ----------------- | --------------------------------- |\n| Query Speed       | **431-1147x** faster with indexes |\n| Storage Options   | Memory, SQLite, WiredTiger, File  |\n| Test Coverage     | 800+ passing tests                |\n| Dependencies      | Zero (core library)               |\n| TypeScript        | Full support with IntelliSense    |\n| API Compatibility | Mongoose-like (easy migration)    |\n\n## Quick Start\n\n```typescript\nimport { Schema, model } from 'memgoose'\n\n// Define schema with indexes, virtuals, and hooks\nconst userSchema = new Schema({ firstName: String, lastName: String, email: String, age: Number })\n\nuserSchema.index('email')\nuserSchema.virtual('fullName').get(doc =\u003e `${doc.firstName} ${doc.lastName}`)\nuserSchema.pre('save', ({ doc }) =\u003e {\n  doc.email = doc.email.toLowerCase() // Normalize email\n})\n\n// Create model\nconst User = model('User', userSchema)\n\n// Insert and query\nawait User.create({ firstName: 'Alice', lastName: 'Smith', email: 'ALICE@EXAMPLE.COM', age: 25 })\nconst user = await User.findOne({ email: 'alice@example.com' }) // O(1) with index!\nconsole.log(user.fullName) // \"Alice Smith\" (virtual property)\n\n// Update, delete, count\nawait User.updateOne({ firstName: 'Alice' }, { $inc: { age: 1 } })\nawait User.deleteMany({ age: { $lt: 18 } })\nconst count = await User.countDocuments({ age: { $gte: 18 } })\n```\n\n## Why memgoose?\n\n- 🚀 **Blazing Fast**: O(1) lookups with indexing (83-1147x faster than linear scans)\n- 🎯 **Type-Safe**: Full TypeScript support with IntelliSense\n- 🏗️ **Mongoose-Compatible**: Drop-in replacement for mongoose in many cases\n- 💾 **Pluggable Storage**: Memory, SQLite, WiredTiger, or file-based (NDJSON + WAL) persistence\n- 📦 **Zero Dependencies**: No runtime dependencies (optional peer dependencies for storage backends)\n- 🧪 **Well Tested**: 800+ passing tests with comprehensive coverage\n\n## Use Cases\n\n- 🧪 **Testing**: Mock MongoDB in unit/integration tests without spinning up a database\n- 🚀 **Prototyping**: Quickly build features before implementing real database\n- 💾 **Caching**: In-memory cache with familiar mongoose-like API\n- 📊 **Development**: Fast local development without database setup\n- 🎯 **Learning**: Learn MongoDB query patterns without installing MongoDB\n- 🗄️ **Persistence**: Use SQLite or WiredTiger for lightweight persistent applications\n\n## Features\n\n- 🔍 **Rich Queries**: MongoDB-like operators (`$eq`, `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$regex`, `$exists`, `$size`, `$elemMatch`, `$all`)\n- 🧮 **Logical Operators**: `$or`, `$and`, `$nor`, `$not` for complex query logic\n- ✏️ **Update Operators**: `$set`, `$unset`, `$inc`, `$dec`, `$push`, `$pull`, `$addToSet`, `$pop`, `$rename`\n- 📈 **Smart Indexing**: Single-field, compound, unique, and TTL indexes with partial matching\n- 📊 **Aggregation Pipeline**: Full pipeline with `$match`, `$group`, `$project`, `$lookup`, `$unwind`, and more\n- 🔗 **Advanced Populate**: Nested populate with select, match filtering, and field projection\n- ⏱️ **TTL Indexes**: Automatic document expiration for sessions, caches, and temporary data\n- 🎣 **Hooks**: Pre/post hooks for save, update, delete, and find operations\n- 🔮 **Virtuals**: Computed properties with getter functions\n- ⚡ **Atomic Operations**: `findOneAndUpdate()`, `findOneAndDelete()`\n- 🚄 **Lean Queries**: 17.5x faster by skipping virtual computation\n\n## Installation\n\n```bash\nnpm install memgoose\n```\n\nFor persistent storage (optional):\n\n```bash\n# SQLite storage\nnpm install better-sqlite3\n\n# WiredTiger storage (requires build tools)\nnpm install memgoose-wiredtiger\n```\n\n## Examples\n\n```bash\n# Basic usage\nnpm run example\n\n# Performance benchmark\nnpm run example:perf\n\n# Memory usage demo\nnpm run example:memory\n\n# Complete features showcase\nnpm run example:showcase\n```\n\nSee the [`examples/`](./examples/) folder for complete, runnable code samples demonstrating all features.\n\n## Documentation\n\n📚 **[Complete Documentation](./docs/README.md)**\n\n- **[Getting Started](./docs/GETTING_STARTED.md)** - Installation and basic usage\n- **[API Reference](./docs/API.md)** - Complete API documentation\n- **[Schemas](./docs/SCHEMAS.md)** - Schema definition and validation\n- **[Queries](./docs/QUERIES.md)** - Query operators and patterns\n- **[Aggregation](./docs/AGGREGATION.md)** - Aggregation pipeline guide\n- **[Storage](./docs/STORAGE.md)** - Storage backends comparison\n- **[Performance](./docs/PERFORMANCE.md)** - Optimization and benchmarks\n- **[Advanced Features](./docs/ADVANCED.md)** - Hooks, virtuals, populate\n\n## Storage Options\n\n```typescript\nimport { connect } from 'memgoose'\n\n// Memory (default, fastest)\nconnect({ storage: 'memory' })\n\n// SQLite (persistent, ACID)\nconnect({ storage: 'sqlite', sqlite: { dataPath: './data' } })\n\n// WiredTiger (enterprise-grade)\nconnect({ storage: 'wiredtiger', wiredtiger: { dataPath: './data' } })\n\n// File (NDJSON + WAL)\nconnect({ storage: 'file', file: { dataPath: './data' } })\n```\n\n## Performance\n\nmemgoose delivers **exceptional performance** through intelligent indexing and optimized query execution.\n\n### Benchmark Results\n\n**Dataset:** 100,000 documents  \n**Hardware:** Apple M4 Max (16 cores, 128GB RAM)  \n**Node.js:** v24.8.0\n\n| Operation                     | Without Index | With Index | Speedup      |\n| ----------------------------- | ------------- | ---------- | ------------ |\n| Equality query (`findOne`)    | 2.01ms        | \u003c0.01ms    | **431x** ⚡  |\n| Compound query (`city + age`) | 2.01ms        | \u003c0.01ms    | **1147x** 🚀 |\n| Count documents               | 24.42ms       | 11.60ms    | **2x**       |\n| Update one document           | 2.09ms        | 0.02ms     | **83x**      |\n| Lean queries (no virtuals)    | 12.00ms       | 0.70ms     | **17.5x**    |\n\n### Key Takeaways\n\n- **Index your queries**: Add `.index('fieldName')` to your schema for O(1) lookups\n- **Use lean queries**: Skip virtual computation for read-heavy operations (17.5x faster)\n- **Choose the right storage**: Memory for testing, SQLite/WiredTiger for production\n\nSee [Performance Guide](./docs/PERFORMANCE.md) for optimization strategies and detailed benchmarks.\n\n## Migration from Mongoose\n\nmemgoose is designed to be Mongoose-compatible:\n\n```typescript\n// Mongoose\nimport mongoose from 'mongoose'\nconst User = mongoose.model('User', userSchema)\n\n// memgoose (mostly the same!)\nimport { model } from 'memgoose'\nconst User = model('User', userSchema)\n```\n\n## Contributing\n\nContributions welcome! Please feel free to submit a Pull Request.\n\n## License\n\nMIT\n\n---\n\n**Need help?** Check out the [examples](./examples/) or [open an issue](https://github.com/dashersw/memgoose/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashersw%2Fmemgoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashersw%2Fmemgoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashersw%2Fmemgoose/lists"}