Skip to content

Query Operators

Master MongoDB-style query operators in @arcaelas/collection.

Comparison Operators

$eq (Equal)

collection.filter({ age: { $eq: 25 } });
// or shorthand
collection.filter({ age: 25 });

$gt (Greater Than)

collection.filter({ age: { $gt: 18 } });

$gte (Greater Than or Equal)

collection.filter({ age: { $gte: 18 } });

$lt (Less Than)

collection.filter({ age: { $lt: 65 } });

$lte (Less Than or Equal)

collection.filter({ age: { $lte: 65 } });

Logical Operators

$not (Not)

collection.filter({ 
  $not: { age: { $lt: 18 } }
});

$in (In Array)

collection.filter({
  status: { $in: ['active', 'pending', 'verified'] }
});

$contains (Contains)

collection.filter({
  skills: { $contains: 'TypeScript' }
});

Operator Aliases

For convenience, use shorthand aliases:

// These are equivalent
collection.where('age', '>=', 18);
collection.filter({ age: { $gte: 18 } });
Alias Operator Meaning
= $eq Equal
!= $not Not equal
> $gt Greater than
< $lt Less than
>= $gte Greater or equal
<= $lte Less or equal
in $in In array
includes $includes Contains

Next: Aggregation Methods