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

balrok

v1.3.0

Published

mongoose helper for heavy lifting of un-indexed collections

Downloads

13

Readme

Balrok

What?

Balrok is a mongoose helper for heavy lifting of un-indexed collections.

Why?

Large MongoDB collections work very well, if you have enough RAM and the fields you are filtering for are indexed. However that is very often not the case and that might result in a lot of frustration, besides frying your cluster or getting no results for minutes of query time.

Balrok helps you very easily to run your aggregations and filters using your client in a safe and efficient manner. It ships with a distributed query processing stack, as well as its own cache collection for your query result.

How ?

You can simply spin up your mongoose setup as you are used to, as soon as you are connected to MongoDB you create a new instance of Balrok and call init to prepare it. When you are ready to go, you can pass your large un-indexed queries straight to your Balrok instance's resolve method. Balrock will stream your documents from batch find queries and call your document operation function on every document, the results are stored in the cache collection and shared with all instances. If another instance of your code is already running the same query, balrok will await the results of that instances process before returning them.

Example

    const balrok = new Balrok({
        cacheCollectionName: "balrok_cache_test",
        cacheTimeMs: 60 * 1000 * 5,
        maxParallelProcesses: 5,
    });

    await balrok.init();

    const query = { /* to resolve fast queries, these should only contain indexed fields */ };

    const documentOperation = (doc: any) => {
        /* instead the actually filtering is done in the streamed document operation */
        return doc.firstName === "Chris";
    };

    const resolveOptions = {
        options: {}, // mongoose find options
        batchSize: 12, // default is 512
        order: -1, // default is -1
        timeoutMs: 5000, // default is 3 minutes
        dontAwait: true, // default is false
        noCache: false, // default is false
        limit: 2, // default is null (which will not apply any limit)
    };

    const results = await balrok.filter(testModel, query, "aQueryName", documentOperation, resolveOptions));

    /* Other available operations:
        - await balrok.filter()
        - await balrok.reduce()
        - await balrok.map()
        - await balrok.resolve() // combines filter and map
    */

A full running sample (with mongoose connection) can be found here.