MongoDB Query API

MongoDB Tutorial

MongoDB Query API

The MongoDB Query API is the set of methods and operators used to create, read, update, and delete (CRUD) data in MongoDB.

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

OperatorMeaning
$eqequal
$nenot equal
$gtgreater than
$gtegreater than or equal
$ltless than
$lteless than or equal
$inin array
$ninnot 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

You may also like...