Paste any SQL query and get the MongoDB equivalent instantly. Supports SELECT, INSERT, UPDATE, DELETE, GROUP BY, HAVING, LIKE, IN, IS NULL and more.
此工具可帮助您将标准SQL(结构化查询语言)查询转换为MongoDB(一种流行的NoSQL文档数据库)使用的等效查询语法。它专为正在转型或同时使用关系数据库和MongoDB的开发人员设计。
在输入框中输入您的SQL查询,相应的MongoDB查询将在下方生成。得益于先进的SQL解析器,此工具现在可以处理更复杂的查询,包括基本聚合和各种WHERE子句。
支持的SQL操作(增强版)Translates column selection and WHERE conditions into a MongoDB find() call with query filter and projection.
ORDER BY becomes sort(), LIMIT becomes limit(), OFFSET becomes skip().
GROUP BY with aggregate functions (COUNT, SUM, AVG, MIN, MAX) is translated into a MongoDB aggregation pipeline.
HAVING filters are translated into a second $match stage in the aggregation pipeline, applied after grouping.
SQL LIKE patterns with % (any characters) and _ (single character) are converted to MongoDB regular expressions.
Full support for IN/$in, NOT IN/$nin, IS NULL/{$eq:null}, IS NOT NULL/{$ne:null}, AND/$and, OR/$or.
Single-row INSERT becomes insertOne(). Multi-row INSERT becomes insertMany(). Column names become document field names.
SQL SET clauses become MongoDB $set operators. The WHERE condition becomes the filter document.
DELETE FROM with a WHERE condition becomes deleteMany(). Use with care — no WHERE deletes all documents.
| SQL Operator | MongoDB Operator | Notes |
|---|---|---|
| = | $eq (or implicit) | Exact match |
| != / <> | $ne | Not equal |
| > | $gt | Greater than |
| >= | $gte | Greater than or equal |
| < | $lt | Less than |
| <= | $lte | Less than or equal |
| IN (...) | $in | Value in list |
| NOT IN (...) | $nin | Value not in list |
| LIKE '%x%' | $regex: /.*x.*/ | % → .*, _ → . |
| NOT LIKE | $not: /pattern/ | Negated regex |
| IS NULL | field: null | Includes missing fields |
| IS NOT NULL | $ne: null | Field exists and is not null |
| AND | $and | All conditions must match |
| OR | $or | Any condition must match |
| COUNT(*) | $sum: 1 | In $group stage |
| SUM(f) | $sum: "$f" | In $group stage |
| AVG(f) | $avg: "$f" | In $group stage |
| MIN(f) | $min: "$f" | In $group stage |
| MAX(f) | $max: "$f" | In $group stage |
| ORDER BY ASC | sort({ f: 1 }) | Ascending |
| ORDER BY DESC | sort({ f: -1 }) | Descending |
| LIMIT n | limit(n) | |
| OFFSET n | skip(n) |
Moving from MySQL, PostgreSQL or SQLite to MongoDB? This tool helps you translate your existing query logic quickly and accurately, reducing the risk of errors during migration.
If you know SQL, this converter shows you exactly how each SQL concept maps to MongoDB's document model — making it the fastest way to learn MongoDB query syntax.
Even experienced MongoDB developers sometimes think in SQL first. Use this tool as a quick reference to translate your mental model into the correct MongoDB syntax.
Share converted queries with teammates who come from a SQL background. A common language reduces friction when working across different database ecosystems.