How to use the SQL to MongoDB Query Converter
- 1. Type a SQL queryA SELECT on one table with WHERE, GROUP BY, ORDER BY or LIMIT.
- 2. ConvertEach clause is mapped to its MongoDB equivalent.
- 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,$lteand$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 BYwith COUNT, SUM, AVG, MIN or MAX → anaggregate()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.