Skip to content

Operators Reference

Complete operator reference for all filtering capabilities

Quick navigation to operator categories:

Operator Categories

Comparison Operators

Numeric and value comparisons

  • $gt, $gte, $lt, $lte, $eq, $ne

Array Operators

Array membership and operations

  • $in, $nin, $contains, $size

String Operators

String matching and patterns

  • $startsWith, $endsWith, $contains, $regex, $match

Logical Operators

Complex query composition

  • $and, $or, $not

Geospatial Operators

Location-based filtering

  • $near, $geoBox, $geoPolygon

Datetime Operators

Temporal filtering

  • $recent, $upcoming, $dayOfWeek, $timeOfDay, $age

Quick Reference Table

OperatorCategoryDescriptionExample
$gtComparisonGreater than{ age: { $gt: 18 } }
$gteComparisonGreater than or equal{ age: { $gte: 21 } }
$ltComparisonLess than{ price: { $lt: 100 } }
$lteComparisonLess than or equal{ price: { $lte: 99.99 } }
$eqComparisonEqual to{ status: { $eq: 'active' } }
$neComparisonNot equal to{ role: { $ne: 'guest' } }
$inArrayValue in array{ city: { $in: ['Berlin', 'Paris'] } }
$ninArrayValue not in array{ status: { $nin: ['archived', 'deleted'] } }
$containsArray/StringContains value/substring{ tags: { $contains: 'urgent' } }
$sizeArrayArray length{ items: { $size: 5 } }
$startsWithStringStarts with string{ email: { $startsWith: 'admin' } }
$endsWithStringEnds with string{ file: { $endsWith: '.pdf' } }
$regexStringRegex match{ phone: { $regex: /^\+1/ } }
$matchStringRegex match (alias){ username: { $match: '^[a-z]+$' } }
$andLogicalAll conditions match{ $and: [...] }
$orLogicalAny condition matches{ $or: [...] }
$notLogicalNegates condition{ $not: { ... } }
$nearGeospatialProximity search{ location: { $near: { center, radius } } }
$geoBoxGeospatialBounding box{ location: { $geoBox: { sw, ne } } }
$geoPolygonGeospatialPolygon containment{ location: { $geoPolygon: { points } } }
$recentDateTimeRecent time period{ date: { $recent: { days: 7 } } }
$upcomingDateTimeFuture time period{ date: { $upcoming: { hours: 24 } } }
$dayOfWeekDateTimeDay of week (0-6){ date: { $dayOfWeek: [1,2,3,4,5] } }
$timeOfDayDateTimeHour range (0-23){ time: { $timeOfDay: { start: 9, end: 17 } } }
$ageDateTimeAge calculation{ birthDate: { $age: { min: 18 } } }
$isWeekdayDateTimeIs weekday{ date: { $isWeekday: true } }
$isWeekendDateTimeIs weekend{ date: { $isWeekend: true } }

Operator Compatibility

Type-Specific Operators

TypeScript provides intelligent autocomplete based on property types:

typescript
interface Product {
  name: string;      // String operators available
  price: number;     // Comparison operators available
  tags: string[];    // Array operators available
  inStock: boolean;  // Comparison operators available
  location: GeoPoint; // Geospatial operators available
  createdAt: Date;   // DateTime operators available
}

filter(products, {
  name: { $startsWith: 'Pro' },        // ✅ String operator
  price: { $gte: 100, $lte: 500 },     // ✅ Comparison operators
  tags: { $contains: 'sale' },         // ✅ Array operator
  inStock: { $eq: true },              // ✅ Comparison operator
  location: { $near: { ... } },        // ✅ Geospatial operator
  createdAt: { $recent: { days: 7 } }  // ✅ DateTime operator
});

Combining Operators

Multiple Operators on Same Field

typescript
// Range query
filter(products, {
  price: { $gte: 100, $lte: 500 }
});

// String pattern with negation
filter(files, {
  name: { $startsWith: 'report', $endsWith: '.pdf' }
});

Multiple Fields with Operators

typescript
filter(products, {
  price: { $gte: 100 },
  category: { $in: ['Electronics', 'Books'] },
  inStock: { $eq: true },
  rating: { $gte: 4.0 }
});

Logical Operators

typescript
filter(products, {
  $and: [
    { price: { $gte: 100 } },
    { $or: [
      { category: 'Electronics' },
      { category: 'Books' }
    ]}
  ]
});

See Also

Released under the MIT License.