#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · LEARN MONGO FAST

SQL to MongoDB Converter: Write a Query You Know, Get the Mongo Version

Type a SQL SELECT and see the matching MongoDB shell query.

  • 🔄 find, count, distinct, aggregate
  • 🧮 GROUP BY to $group
  • 🔤 LIKE to $regex

How to use the SQL to MongoDB Query Converter

  1. 1. Type a SQL queryA SELECT on one table with WHERE, GROUP BY, ORDER BY or LIMIT.
  2. 2. ConvertEach clause is mapped to its MongoDB equivalent.
  3. 3. Copy the queryRun it in mongosh or adapt it for your driver.

How SQL maps to MongoDB

  • SELECT a, b → a projection { a: 1, b: 1, _id: 0 }; SELECT * → no projection.
  • WHERE x = 5 → { x: 5 }; > >= < <= and != → $gt, $gte, $lt, $lte and $ne.
  • AND → fields side by side (or $and); OR → $or; NOT → $nor.
  • IN / NOT IN → $in / $nin; BETWEEN → $gte + $lte.
  • LIKE 'A%' → $regex: '^A'; IS NULL → null.
  • ORDER BY … DESC → .sort({ … : -1 }); LIMIT/OFFSET → .limit()/.skip().
  • COUNT(*) → countDocuments(); GROUP BY with COUNT, SUM, AVG, MIN or MAX → an aggregate() pipeline with $group.

Worked example

The sample query selects name, email and city of students aged 18 or more in Noida or Delhi whose name starts with A, sorted by age descending, top 10. It becomes:

db.students.find({
  age: { $gte: 18 },
  city: { $in: ['Noida', 'Delhi'] },
  name: { $regex: '^A', $options: 'i' }
}, { name: 1, email: 1, city: 1, _id: 0 }).sort({ age: -1 }).limit(10)

Try SELECT city, COUNT(*) AS total FROM students GROUP BY city to see an aggregate pipeline with $group: { _id: '$city', total: { $sum: 1 } }. JOINs and subqueries are not converted; MongoDB handles those with $lookup or by embedding documents, which needs design decisions a converter can't make for you.

Frequently asked questions

Why is LIKE case-insensitive here?

Most SQL databases compare text case-insensitively by default, so $options: 'i' gives the closest match. Remove it for exact case.

Will the regex use an index?

Only anchored, case-sensitive patterns like ^A use an index well. Case-insensitive or %text% patterns scan more documents.

Does it support JOIN?

No. Use $lookup in an aggregation pipeline, or embed related data in the document.

Is the sql to mongodb query converter free?

Yes, it is free. Your first conversion asks for your name and WhatsApp number once, and after that the sql to mongodb query converter and every other Uncodemy tool open without the form.

More free tools

See all free tools