SQL to MongoDB Converter — Translate SQL Queries into Aggregation Pipelines & find().
Convert SQL SELECT, WHERE, JOIN, GROUP BY, HAVING, ORDER BY, and LIMIT queries into ready-to-run mongosh, MongoDB Compass JSON, and Node.js driver pipelines locally in your browser.
MongoDB can only leverage collection indexes when $match and $sort appear at the beginning of the pipeline before $lookup or $group. This converter automatically emits your WHERE filter as the very first stage.
2. Handling JOINs with $lookup
An INNER JOIN unwinds matched documents without empty arrays, whereas a LEFT JOIN sets preserveNullAndEmptyArrays: true so parent documents without a match are kept—matching standard SQL join semantics.
All SQL tokenization, AST translation, and formatting happen directly inside your browser—safe for proprietary production schemas and confidential query logic.
Frequently Asked Questions
How does SQL translate to a MongoDB aggregation pipeline?
Each SQL clause maps cleanly to a MongoDB aggregation stage: WHERE becomes $match, JOIN becomes $lookup (paired with $unwind), GROUP BY and aggregate functions (COUNT, SUM, AVG, MIN, MAX) become $group, HAVING becomes a post-group $match, SELECT becomes $project, ORDER BY becomes $sort, OFFSET becomes $skip, and LIMIT becomes $limit.
Can I paste the JSON Pipeline directly into MongoDB Compass or Atlas?
Yes. Switch the output tab to "JSON Pipeline" to copy a strict JSON array of stages that pastes directly into MongoDB Compass’s Aggregation Pipeline Builder or MongoDB Atlas Data Explorer.
When does the converter also show a db.collection.find() equivalent?
Whenever your SQL query does not require grouping (GROUP BY / aggregates / DISTINCT) or table joins (JOIN), the mongosh tab automatically outputs both the aggregation pipeline and the simpler db.collection.find(...).sort(...).skip(...).limit(...) query.
How are SQL LIKE, IN, BETWEEN, and IS NULL operators converted?
LIKE and ILIKE convert to $regex (with $options: "i" for ILIKE), IN and NOT IN convert to $in and $nin, BETWEEN converts to { $gte, $lte }, and IS NULL / IS NOT NULL convert to null equality or { $ne: null }.
Are my SQL queries or database schema names uploaded to any server?
No. SQL parsing and MongoDB pipeline generation run 100% locally in your browser. Your queries, table names, and filter values never leave your device.