Filtering allows you to retrieve only the data that matches specific conditions. The NestJS CRUD framework provides a comprehensive set of operators for building simple to complex filters.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nestjsx/crud/llms.txt
Use this file to discover all available pages before exploring further.
Basic Syntax
Filters use the following format:- field: The name of the field to filter
- operator: The comparison operator to use
- value: The value to compare against (optional for some operators)
Example
Comparison Operators
The framework supports both modern ($ prefixed) and deprecated operators.
Equality Operators
| Operator | Modern | Description | Example | ||||
|---|---|---|---|---|---|---|---|
eq | $eq | Equals | `filter=name | $eq | John` | ||
ne | $ne | Not equals | `filter=status | $ne | inactive` |
Comparison Operators
| Operator | Modern | Description | Example | ||||
|---|---|---|---|---|---|---|---|
gt | $gt | Greater than | `filter=age | $gt | 18` | ||
gte | $gte | Greater than or equal | `filter=age | $gte | 18` | ||
lt | $lt | Less than | `filter=price | $lt | 100` | ||
lte | $lte | Less than or equal | `filter=price | $lte | 100` |
String Operators
| Operator | Modern | Description | Example | ||||
|---|---|---|---|---|---|---|---|
starts | $starts | Starts with | `filter=name | $starts | Jo` | ||
ends | $ends | Ends with | `filter=email | $ends | @gmail.com` | ||
cont | $cont | Contains | `filter=description | $cont | keyword` | ||
excl | $excl | Excludes | `filter=name | $excl | test` |
Case-Insensitive String Operators
All string operators have case-insensitive variants with theL suffix:
| Operator | Description | Example | ||||
|---|---|---|---|---|---|---|
$eqL | Equals (case-insensitive) | `filter=name | $eqL | john` | ||
$neL | Not equals (case-insensitive) | `filter=name | $neL | john` | ||
$startsL | Starts with (case-insensitive) | `filter=name | $startsL | jo` | ||
$endsL | Ends with (case-insensitive) | `filter=email | $endsL | @gmail.com` | ||
$contL | Contains (case-insensitive) | `filter=description | $contL | laptop` | ||
$exclL | Excludes (case-insensitive) | `filter=name | $exclL | test` |
Array Operators
| Operator | Modern | Description | Example | ||||
|---|---|---|---|---|---|---|---|
in | $in | In array | `filter=status | $in | active,pending` | ||
notin | $notin | Not in array | `filter=role | $notin | guest,banned` | ||
between | $between | Between values | `filter=age | $between | 18,65` |
Case-Insensitive Array Operators
| Operator | Description | Example | ||||
|---|---|---|---|---|---|---|
$inL | In array (case-insensitive) | `filter=status | $inL | active,pending` | ||
$notinL | Not in array (case-insensitive) | `filter=role | $notinL | guest,banned` |
Null Operators
| Operator | Modern | Description | Example | ||
|---|---|---|---|---|---|
isnull | $isnull | Is null | `filter=deletedAt | $isnull` | |
notnull | $notnull | Is not null | `filter=email | $notnull` |
Null operators do not require a value parameter. The syntax is:
filter={field}||{operator}Multiple Filters (AND)
You can apply multiple filters to create AND conditions:OR Conditions
Use theor parameter for OR logic:
Combining AND and OR
You can combine bothfilter (AND) and or parameters:
isActive = true AND (name = 'John' OR name = 'Jane')
Advanced Search
For complex queries, use thes (search) parameter with JSON:
Simple Search
With Operators
Complex OR Conditions
Nested AND Conditions
Filtering Nested Fields
You can filter by nested object fields using dot notation:Type Conversion
Values are automatically parsed to the correct type:Practical Examples
E-commerce Filters
User Management
Content Management
Error Handling
Invalid filters will throw aRequestQueryException:
Best Practices
- Use modern operators: Prefer
$eq,$gt, etc. over deprecated operators - Use case-insensitive operators: Use
$eqL,$contLfor user input to avoid case sensitivity issues - Validate user input: Always validate and sanitize filter values from user input
- Index filtered fields: Add database indexes to fields commonly used in filters
- Combine with pagination: Always use
limitwhen filtering to prevent large result sets - Use appropriate operators: Choose the right operator for the data type (e.g.,
$betweenfor ranges)
Next Steps
Sorting
Learn how to sort filtered results
Pagination
Paginate through filtered data
Relations
Filter related entities with joins
Query Parameters
Overview of all query parameters