MongoDB Query API

MongoDB Query API
It is powerful, flexible, and easy to use compared to traditional SQL queries.
Basic Query Structure
query → filter condition
projection → fields to include or exclude
Read Operations (Find)
Find all documents
Find with condition
Find one document
Projection (Select Specific Fields)
Include fields:
Exclude field:
Comparison Query Operators
| Operator | Meaning |
|---|---|
$eq | equal |
$ne | not equal |
$gt | greater than |
$gte | greater than or equal |
$lt | less than |
$lte | less than or equal |
$in | in array |
$nin | not in array |
Example:
Logical Query Operators
$and
$or
$not
Element Query Operators
$exists
$type
Array Query Operators
$all
$size
Update Operations
Update one
Update many
Increment value
Delete Operations
Delete one
Delete many
Sorting, Limiting & Skipping
Sort
Limit
Skip
Regular Expression (Search)
Count Documents
SQL vs MongoDB Query Example
SQL
MongoDB
Summary
MongoDB Query uses JSON-like syntax
Supports rich operators
Faster and flexible than SQL
Ideal for modern applications
