Filter Operators

Comparison Operators

OperatorDescriptionExampleUse Case
$eqEquals{ "age": { "$eq": 25 } }Exact match
$neNot equal{ "status": { "$ne": "inactive" } }Exclude specific values
$gtGreater than{ "price": { "$gt": 100 } }Minimum threshold
$gteGreater than or equal{ "rating": { "$gte": 4.0 } }Minimum inclusive threshold
$ltLess than{ "quantity": { "$lt": 10 } }Maximum threshold
$lteLess than or equal{ "discount": { "$lte": 0.5 } }Maximum inclusive threshold
$inMatches any value in array{ "category": { "$in": ["electronics", "books"] } }Multiple value selection
$ninDoes not match any value in array{ "status": { "$nin": ["deleted", "banned"] } }Exclude multiple values

Logical Operators

OperatorDescriptionExampleUse Case
$andLogical AND (all conditions true){ "$and": [{"age": {"$gte": 18}}, {"status": "active"}] }Multiple requirements
$orLogical OR (any condition true){ "$or": [{"premium": true}, {"discount": {"$gt": 0.2}}] }Alternative conditions
$notLogical NOT (condition false){ "email": { "$not": { "$regex": "@spam.com" } } }Negation
$norLogical NOR (none of conditions true){ "$nor": [{"deleted": true}, {"banned": true}] }Exclude multiple conditions

Array Operators

OperatorDescriptionExampleUse Case
$allContains all specified elements{ "tags": { "$all": ["premium", "verified"] } }All elements must be present
$elemMatchArray element matches condition{ "orders": { "$elemMatch": { "amount": { "$gt": 100 } } } }Complex array element filtering
$sizeArray size equals value{ "items": { "$size": 3 } }Exact array length

Text and Pattern Operators

OperatorDescriptionExampleUse Case
$regexRegular expression match{ "name": { "$regex": "^John", "$options": "i" } }Pattern matching
$textFull-text search{ "$text": { "$search": "mongodb tutorial" } }Text search across indexed fields

Existence and Type Operators

OperatorDescriptionExampleUse Case
$existsField exists{ "email": { "$exists": true } }Check field presence
$typeField type check{ "price": { "$type": "number" } }Data type validation

Advanced Operators

OperatorDescriptionExampleUse Case
$exprExpression-based queries{ "$expr": { "$gt": ["$spent", "$budget"] } }Compare fields within document
$jsonSchemaJSON Schema validation{ "$jsonSchema": { "required": ["name", "email"] } }Document structure validation
$modModulo operation{ "quantity": { "$mod": [5, 0] } }Divisibility checks

On this page