TypeScript Ready

mongoose-qb

A powerful and extensible query builder for Mongoose

Simplify complex query operations like filtering, searching, sorting, pagination and field projection — all from HTTP query parameters.

npm versionnpm downloadsLicense

Concept

Build flexible and clean Mongoose queries from HTTP query parameters.

Example Request

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

Features

Build flexible and clean Mongoose queries from HTTP query parameters

Full-text Search
Search across specified fields with flexible query syntax
Dynamic Filtering
Exact match filtering on any model field
Flexible Sorting
Sort by any field with ascending or descending order
Field Projection
Limit returned fields for optimized responses
Pagination with Meta
Built-in pagination with comprehensive metadata
Population Support
Populate related documents including nested paths
TypeScript Support
Full type safety with strict TypeScript definitions
Built-in Handler
Ready-to-use useQuery function for instant integration
Custom Factory
Optional createQuery factory for custom configurations
API Reference

Supported Query Parameters

All available parameters for building dynamic queries

ParameterTypeExampleDescription
searchstringsearch=sundarbanSearches across configured fields
filterstringtitle=Beach HolidayExact match filtering on any field
sortstringsort=-createdAt,priceSort with - prefix for descending
fieldsstringfields=title,priceField projection (select specific fields)
pagenumberpage=2Page number for pagination
limitnumberlimit=20Number of items per page
Code Examples

Usage Examples

Common patterns and use cases with TypeScript

Loading...

Use the built-in handler to query any Mongoose model with full configuration options

Customization

Configuration Options

Available options for customizing query behavior

OptionTypeDescription
searchArray<string>Fields to search in
fieldsbooleanEnable field projection
filterbooleanEnable exact match filtering
sortbooleanEnable sorting
paginatebooleanEnable pagination
populateArray<IQBPopulate>Population configuration
excludesArray<keyof T>Fields to exclude from results

Type Definition

IQBPopulate = { path: string; select?: string; }