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.
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=20Features
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
| Parameter | Type | Example | Description |
|---|---|---|---|
| search | string | search=sundarban | Searches across configured fields |
| filter | string | title=Beach Holiday | Exact match filtering on any field |
| sort | string | sort=-createdAt,price | Sort with - prefix for descending |
| fields | string | fields=title,price | Field projection (select specific fields) |
| page | number | page=2 | Page number for pagination |
| limit | number | limit=20 | Number 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
| 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> | Fields to exclude from results |
Type Definition
IQBPopulate = { path: string; select?: string; }