MongoDB Query Operators

MongoDB Query Operators 📘

In MongoDB, query operators are special keywords (starting with $) used to filter, match, and manipulate documents in queries like find(), update(), and delete().

1️⃣ Comparison Operators

Used to compare field values.

OperatorDescription
$eqEqual to
$neNot equal to
$gtGreater than
$gteGreater than or equal
$ltLess than
$lteLess than or equal
$inValue in array
$ninValue not in array

Example



 


2️⃣ Logical Operators

Used to combine multiple conditions.

OperatorDescription
$andAll conditions true
$orAny condition true
$notNegates condition
$norNone of the conditions true

Example



 


3️⃣ Element Operators

Used to check field existence or data type.

OperatorDescription
$existsField exists or not
$typeField data type

Example



 


4️⃣ Array Operators

Used for querying array fields.

OperatorDescription
$allMatches all array values
$sizeArray length
$elemMatchMatch embedded array condition

Example



 


5️⃣ Evaluation Operators

Used for expressions and pattern matching.

OperatorDescription
$regexPattern matching
$exprUse expressions
$modModulo operation
$textText search

Example



 


6️⃣ Update Operators (Used in Update Queries)

OperatorPurpose
$setSet field value
$unsetRemove field
$incIncrement value
$pushAdd to array
$pullRemove from array

Example



 


7️⃣ Projection Operators

Used to control returned fields.



 


SQL vs MongoDB Operators

SQLMongoDB
=$eq
!=$ne
>$gt
<$lt
IN$in
LIKE$regex

Quick Recap 🧠

  • Operators start with $

  • Used in find, update, delete

  • Powerful & flexible

  • Replace complex SQL conditions

You may also like...