Desi Consultancies

Mongo DB Quries

Feature MongoDB MySQL
Data Model Document-based Relational
Query Language MongoDB Query Language (MQL) Structured Query Language (SQL)
Indexing Supports rich query capabilities through secondary indexes Supports basic indexing through B-Tree indexes
Finding Documents db.collection.find({key: value}) SELECT * FROM table WHERE column = value
Finding Documents with LIKE Not supported SELECT * FROM table WHERE column LIKE ‘%value%’
Scalability Scales horizontally through sharding Scales vertically through increasing hardware resources
Transactions Supports multi-document transactions Supports ACID (Atomicity, Consistency, Isolation, Durability) transactions through InnoDB Engine.
Data Aggregation Supports powerful aggregation framework Supports basic data aggregation through GROUP BY and aggregate functions (SUM, AVG, COUNT, etc.)
Flexibility Supports dynamic schema, where fields can vary across documents Supports fixed schema, where all records must adhere to the same structure

SQL and MongoDB are both widely used databases, but they have different query languages and operators. Some commonly used SQL operators have equivalent operators in MongoDB, but others, such as the LIKE operator, are not supported. The table above provides a comparison of some of the most commonly used SQL operators and their equivalents in MongoDB, along with a brief description. It is important to understand the differences between these operators when transitioning from SQL to MongoDB or vice versa.


SQL Operator MongoDB Operator
BETWEEN $gte, $lte
EXISTS $exists
NULL $type
COUNT db.collection.count()
SUM db.collection.aggregate([{$group: {_id: null, total: {$sum: “$field”}}}])
AVG db.collection.aggregate([{$group: {_id: null, average: {$avg: “$field”}}}])
MIN db.collection.aggregate([{$group: {_id: null, minimum: {$min: “$field”}}}])
MAX db.collection.aggregate([{$group: {_id: null, maximum: {$max: “$field”}}}])
SQL Operator MongoDB Operator
= $eq
!= $ne
< $lt