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

monkey-db

v0.1.8

Published

A strongly typed, verbose implementation of Mongoose in Typescript.

Downloads

55

Readme

Monkey 🐒 (beta)

A strongly typed, verbose implementation of Mongoose in Typescript.

  • Strongly typed: prevents query mistakes at compile time.
  • Verbose: use natural language to create queries.
  • Flexible: create your own modifiers that fits your needs.
  • Fast: use Mongoose as the engine.
const db = new MongoDB()
await db.connect('mongodb://127.0.0.1/my_database')

const users = await db.perform(
    MongoDBQuery.withModel(userModel)
        .modifier(FindMany.whereKeyEquals('emailVerified', true))
        .modifier(Sort.ascendingBy('name'))
        .modifier(Populate.properties(['friends']))
)

Table of contents

Installation

This package is distributed with npm.

# npm
npm install monkey-db

# yarn
yarn add monkey-db

Documentation

Query modifiers

See all query modifiers in the package documentation.

Performing a request

To perform a request, you'll need to instantiate a MongoDB instance and connect it to your MongoDB database.

const db = new MongoDB()
await db.connect('mongodb://127.0.0.1/my_database')

Then, use the MongoDBQuery with the model corresponding to the collection you want to query.

// Returns all the users
const users = await db.perform(
    MongoDBQuery.withModel(userModel)
        .modifier(FindMany.all())
)

Use query modifiers to add parameters to your query using the .modifier() function. You can chain them, as many as you need, but note that query modifiers are order sensitive. That means you cannot start your query with a Sort modifier. For more infos, see Creating query modifiers.

// Returns all the users sorted by names
const users = await db.perform(
    MongoDBQuery.withModel(userModel)
        .modifier(FindMany.all())
        .modifier(Sort.ascendingBy('name'))
)

Creating query modifiers

Monkey comes with a bunch of query modifiers, but you can easily create your to better fits your needs.

Query modifiers takes an input, and returns a new output. As an output, you usually want to return either a DBQuery or a DBOperation depending of your needs.

  • DBQuery contains a mongooseQuery property that represents a MongoDB query such as finding, sorting or filtering.
  • DBOperation contains a mongooseOperation property that represents a MongoDB operation such as creating, updating or deleting.

Both of these types implements the Performable interface so you can always retrieve the mongoose query you are working with.

export interface Performable<T> {
    databaseQuery: MongooseQuery | MongooseOperation
}

Creating a query

Say you want to create a query that finds all your users with a emailVerified property set to true. You query modifier will take as input your mongoose model, and will output a DBQuery.

Declare the class as the following:

export class FindVerifiedUsers<T extends Document> implement QueryModifier<Model<T>, DBQuery<T>> {}

T is the generic type that represents your mongoose model.

Then implements the modifier() method.

export class FindVerifiedUsers<T extends Document> implement QueryModifier<Model<T>, DBQuery<T>> {
    public modifier(input: Model<T>): DBOperation<T> {
        const query: MongooseQuery = input.find({ emailVerified: true })
        return new DBQuery(query)
    }
}

You can then use your query this way:

// Returns all the users with verified email
const verifiedUsers = await db.perform(
    MongoDBQuery.withModel(userModel)
        .modifier(new FindVerifiedUsers())
)

Creating an operation

Say you want to create an operation that create a new user and set its property emailVerified to true. You query modifier will take as input your mongoose model, and will output a DBQuery.

Declare the class as the following:

export class CreateVerifiedUser<T extends Document> implement QueryModifier<Model<T>, DBOperation<T>> {
    public constructor(data: any) {}
}

T is the generic type that represents your mongoose model.

Then implements the modifier() method.

export class CreateVerifiedUser<T extends Document> implement QueryModifier<Model<T>, DBOperation<T>> {
    public constructor(private readonly data: any) {}

    public modifier(input: Model<T>): DBOperation<T> {
        const operation: MongooseOperation = input.create({ ...this.data, emailVerified: true })
        return new DBOperation(operation)
    }
}

You can then use your operation this way:

// Returns the created user with a `emailVerified` property set to true
const users = await db.perform(
    MongoDBQuery.withModel(userModel)
        .modifier(new CreateVerifiedUser({ username: 'bpisano' }))
)

Contribution

Work is still in progress and contributions to Monkey are open and highly appreciated. When creating new query modifiers, make sure that:

  • It it verbose. Make use of natural language as much as possible. This makes this package easy to get started with.
  • It is generic enough. Try not to implement very specific use case in this package. Remember, anyone can easily create their own query modifier that fits their needs.

Roadmap

  • [ ] Implementing all the the operations and queries used by mongoose as query modifiers.
  • [ ] Improving verbosity of filters. It would be nice to have something like:
FindMany.where(Property.named('username').equals('bpisano'))