Memgoose โ€“ An In-Memory Mongoose Impersonator
github.comยท5hยท
Discuss: Hacker News

memgoose

An in-memory mongoose impersonatorโ€”a lightweight, high-performance in-memory database with MongoDB-like query operators.

Quick Start

import { Schema, model } from 'memgoose'

// Define schema with indexes, virtuals, and hooks
const userSchema = new Schema({ firstName: String, lastName: String, age: Number })

userSchema.index('firstName')
userSchema.virtual('fullName').get(doc => `${doc.firstName} ${doc.lastName}`)
userSchema.pre('save', ({ doc }) => {
doc.createdAt = new Date()
})

// Create model
const User = model('User', userSchema)

// Insert and query
await User.create({ firstName: 'Alice', lastName: 'Smith', age: 25 })
const user = await User.findOne({ firstName: 'Alice' }) // O(1) with index!
console.log(user.fullName) // "Alice Smith" (virtual property)

//...

Similar Posts

Loading similar posts...