SQL INPUT
MONGODB OUTPUT
// MongoDB query will appear here...
// Try an example

Что такое Конвертер SQL в MongoDB?

Этот инструмент помогает вам переводить стандартные SQL (Structured Query Language) запросы в эквивалентный синтаксис запросов, используемый MongoDB, популярной документо-ориентированной NoSQL базой данных. Он предназначен для разработчиков, переходящих на MongoDB или работающих с обоими типами баз данных.

Введите ваш SQL запрос в поле ввода, и соответствующий MongoDB запрос будет сгенерирован ниже. Благодаря продвинутому SQL парсеру, этот инструмент теперь может обрабатывать более сложные запросы, включая базовые агрегации и разнообразные условия WHERE.

Этот конвертер использует библиотеку для парсинга SQL для поддержки более широкого спектра SQL операций:

SELECT

find() — Basic Query

Translates column selection and WHERE conditions into a MongoDB find() call with query filter and projection.

SELECT name, age FROM users WHERE age > 25 db.users.find( { age: { $gt: 25 } }, { name: 1, age: 1, _id: 0 } )
SELECT

sort(), limit(), skip()

ORDER BY becomes sort(), LIMIT becomes limit(), OFFSET becomes skip().

SELECT * FROM products ORDER BY price DESC LIMIT 10 OFFSET 20 db.products.find({}) .sort({ price: -1 }) .skip(20).limit(10)
AGGREGATE

GROUP BY → aggregate()

GROUP BY with aggregate functions (COUNT, SUM, AVG, MIN, MAX) is translated into a MongoDB aggregation pipeline.

SELECT country, COUNT(*) AS total FROM users GROUP BY country db.users.aggregate([ { $group: { _id: { country: "$country" }, total: { $sum: 1 } } } ])
AGGREGATE

HAVING → $match after $group

HAVING filters are translated into a second $match stage in the aggregation pipeline, applied after grouping.

SELECT category, AVG(price) AS avg_p FROM products GROUP BY category HAVING AVG(price) > 50 → pipeline with $group then $match
WHERE

LIKE → $regex

SQL LIKE patterns with % (any characters) and _ (single character) are converted to MongoDB regular expressions.

WHERE name LIKE '%mongo%' { name: { $regex: /.*mongo.*/ } } WHERE code LIKE 'IT_' { code: { $regex: /^IT.$/ } } NOT LIKE { field: { $not: /pattern/ } }
WHERE

IN, IS NULL, AND/OR

Full support for IN/$in, NOT IN/$nin, IS NULL/{$eq:null}, IS NOT NULL/{$ne:null}, AND/$and, OR/$or.

WHERE status IN ('a','b') { status: { $in: ["a","b"] } } WHERE deleted_at IS NULL { deleted_at: null } WHERE a=1 AND b=2 { $and: [{a:1},{b:2}] }
INSERT

insertOne() / insertMany()

Single-row INSERT becomes insertOne(). Multi-row INSERT becomes insertMany(). Column names become document field names.

INSERT INTO users (name, age) VALUES ('Alice', 30) db.users.insertOne({ name: "Alice", age: 30 })
UPDATE

updateMany() with $set

SQL SET clauses become MongoDB $set operators. The WHERE condition becomes the filter document.

UPDATE users SET status = 'active' WHERE id = 42 db.users.updateMany( { id: 42 }, { $set: { status: "active" } } )
DELETE

deleteMany()

DELETE FROM with a WHERE condition becomes deleteMany(). Use with care — no WHERE deletes all documents.

DELETE FROM sessions WHERE expires < '2024-01-01' db.sessions.deleteMany({ expires: { $lt: "2024-01-01" } })

SQL → MongoDB operator reference

SQL Operator MongoDB Operator Notes
=$eq (or implicit)Exact match
!= / <>$neNot equal
>$gtGreater than
>=$gteGreater than or equal
<$ltLess than
<=$lteLess than or equal
IN (...)$inValue in list
NOT IN (...)$ninValue not in list
LIKE '%x%'$regex: /.*x.*/% → .*, _ → .
NOT LIKE$not: /pattern/Negated regex
IS NULLfield: nullIncludes missing fields
IS NOT NULL$ne: nullField exists and is not null
AND$andAll conditions must match
OR$orAny condition must match
COUNT(*)$sum: 1In $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 ASCsort({ f: 1 })Ascending
ORDER BY DESCsort({ f: -1 })Descending
LIMIT nlimit(n)
OFFSET nskip(n)

Зачем конвертировать SQL в MongoDB?

Database Migration

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.

Learning MongoDB

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.

Daily Development

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.

Team Collaboration

Share converted queries with teammates who come from a SQL background. A common language reduces friction when working across different database ecosystems.