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

mongoose-qb

v2.2.9

Published

A lightweight and flexible query builder for Mongoose, enabling easy chaining of search, filter, sort, field selection, and pagination operations.

Readme

Features

  • Full-text search across specified fields
  • Dynamic filtering with exact match
  • Sorting by any model field
  • Field limiting (projection)
  • Pagination with meta info
  • Population support (including nested paths)
  • TypeScript support
  • Built-in handler: useQuery
  • Optional factory: createQuery

Installation

npm install mongoose-qb
# or
yarn add mongoose-qb

Concept

Build flexible and clean Mongoose queries from HTTP query parameters.

Example request:

GET /tours?search=sundarban&sort=-createdAt,price&d=title,price&page=2&limit=20

Supported Query Parameters

| Parameter | Example | Description | | -------------- | ------------------------ | ----------------------------------- | | Search | ?search=sundarban | Searches across configured fields | | Filter | ?title=Beach Holiday | Exact match filtering | | Sort | ?sort=-createdAt,price | Sort with - prefix for descending | | Fields | ?fields=title,price | Field projection | | Pagination | ?page=2&limit=20 | Pagination control |

Population

Supports flat and nested Mongoose populate.

// useQuery option
populate: [
  { path: "author", select: "-__v -password" },
  { path: "comment", select: "-__v" },
  { path: "field.inner", select: "-__v -title" },
];

Exclude sensitive fields:

// useQuery option
excludes: ["password", "_id"];

Usage Examples

Basic Example (with built-in useQuery)

import { useQuery } from "mongoose-qb";

export const retrievePosts = async (query: Record<string, string>) => {
  /* 
     useQuery<T>(model, query, options)
  */
  const post = await useQuery<IPost>(Post, query, {
    fields: true,
    filter: true,
    sort: true,
    paginate: true,
    excludes: ["comments", "likes"],
    search: ["title", "description", "slug"],
    populate: [{ path: "author", select: "-__v" }],
  });

  return post; // returns { meta, data }
};

Custom Query Factory

Create a custom instance in utils/useQuery.ts:

import { createQuery } from "mongoose-qb";

export const useQuery = createQuery({
  defaultLimit: 30,
  defaultPage: 1,
  defaultSortField: "-createdAt",
});

Then use it:

import { useQuery } from "@/utils/useQuery";

export const retrievePosts = async (query: Record<string, string>) => {
  const post = await useQuery<IPost>(Post, query, {
    search: ["title", "description", "slug"],
    fields: true,
    filter: true,
    sort: true,
    paginate: true,
    /* ...more options */
  });

  return post; // returns { meta, data }
};

Response Format

{
  meta: {
    total: number;       // Total documents
    page: number;        // Current page
    limit: number;       // Items per page
    totalPage: number;  // Total pages
  },
  data: Array<T>;       // Your documents
}

Configuration Options

| Option | Type | Description | | ---------- | -------------------- | ---------------------------- | | search | Array<string> | Fields to search in | | fields | boolean | Enable field projection | | filter | boolean | Enable exact match filtering | | sort | boolean | Enable sorting | | paginate | boolean | Enable pagination | | populate | Array<IQBPopulate> | Population configuration | | excludes | Array<keyof T> | Excludes configuration |

License

MIT License © 2025 DevAbabil

Vision

mongoose-qb aims to bring a clean, fluent, and highly customizable querying experience to Mongoose-based applications — reducing boilerplate and unlocking the full potential of query parameters.

Built with ❤️ by DevAbabil