Skip to main content
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.

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

This retrieves all users where the name equals “John”.

Comparison Operators

The framework supports both modern ($ prefixed) and deprecated operators.

Equality Operators

Comparison Operators

String Operators

Case-Insensitive String Operators

All string operators have case-insensitive variants with the L suffix:
Use case-insensitive operators ($eqL, $contL, etc.) when you want to match strings regardless of case.

Array Operators

Case-Insensitive Array Operators

Null Operators

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:
All filter conditions must be satisfied (AND logic).

OR Conditions

Use the or parameter for OR logic:

Combining AND and OR

You can combine both filter (AND) and or parameters:
This translates to: isActive = true AND (name = 'John' OR name = 'Jane') For complex queries, use the s (search) parameter with JSON:

With Operators

Complex OR Conditions

Nested AND Conditions

When using the s (search) parameter, any filter and or parameters are ignored.

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 a RequestQueryException:

Best Practices

  1. Use modern operators: Prefer $eq, $gt, etc. over deprecated operators
  2. Use case-insensitive operators: Use $eqL, $contL for user input to avoid case sensitivity issues
  3. Validate user input: Always validate and sanitize filter values from user input
  4. Index filtered fields: Add database indexes to fields commonly used in filters
  5. Combine with pagination: Always use limit when filtering to prevent large result sets
  6. Use appropriate operators: Choose the right operator for the data type (e.g., $between for 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