Guide

THE TOOLBOX / DATABASE & DATA ENGINEERING

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.

Examples:
Pipeline Stages (6):db.orders→$match→$group→$match (HAVING)→$project→$sort→$limit
SELECT · WHERE · JOIN · GROUP BY · HAVING
db.orders.aggregate([
  {
    "$match": {
      "status": "paid",
      "created_at": {
        "$gte": "2026-01-01"
      }
    }
  },
  {
    "$group": {
      "_id": "$category",
      "order_count": {
        "$sum": 1
      },
      "revenue": {
        "$sum": "$total_amount"
      },
      "avg_order": {
        "$avg": "$total_amount"
      }
    }
  },
  {
    "$match": {
      "revenue": {
        "$gt": 5000
      }
    }
  },
  {
    "$project": {
      "_id": 0,
      "category": "$_id",
      "order_count": 1,
      "revenue": 1,
      "avg_order": 1
    }
  },
  {
    "$sort": {
      "revenue": -1
    }
  },
  {
    "$limit": 10
  }
]);

SQL ↔ MONGODB MAPPING REFERENCE

SQL Clause & Operator to MongoDB Cheat Sheet.

SQL Clause / OperatorMongoDB Stage / OperatorExample
WHERE$match{ "$match": { "status": "paid" } }
LEFT JOIN ... ON$lookup + $unwind{ "$lookup": { "from": "customers", "localField": "customer_id", "foreignField": "_id", "as": "c" } }
GROUP BY + SUM/COUNT$group{ "$group": { "_id": "$category", "revenue": { "$sum": "$total_amount" } } }
HAVING$match (after $group){ "$match": { "revenue": { "$gt": 5000 } } }
SELECT cols$project{ "$project": { "_id": 0, "email": 1 } }
ORDER BY / LIMIT / OFFSET$sort / $limit / $skip{ "$sort": { "revenue": -1 } }, { "$limit": 10 }
IN / BETWEEN / LIKE$in / $gte+$lte / $regex{ "price": { "$gte": 25, "$lte": 150 } }

1. Performance Tip: Place $match Early

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.

4. 100% Client-Side Privacy

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.