SQL to MongoDB Query Converter screenshot

SQL to MongoDB Query Converter

Translate a single SELECT with WHERE, AND, ORDER BY and LIMIT into a MongoDB find expression, refusing joins, grouping and subqueries by name.

Privacy First
0 Runs
Updated 2026-11-22
Runs in your browser
No upload
Deterministic

What this page does

A single-table SELECT maps onto a MongoDB find call almost clause for clause: the column list becomes a projection, the WHERE conditions become a filter document, ORDER BY becomes a sort and LIMIT becomes a limit. This page performs that translation for the plain form and refuses the forms it cannot translate honestly.

How to use it

Paste or type the text and press Run. The result appears beside the form. With "SELECT name, age FROM users WHERE age >= 30 AND city = 'Paris' ORDER BY name ASC LIMIT 10", the page gives:

MongoDB query:
db.users.find({
  "age": { "$gte": 30 },
  "city": "Paris"
}, { "name": 1, "age": 1, "_id": 0 }).sort({ "name": 1 }).limit(10)

Collection:                      users
Filter:                          {   "age": { "$gte": 30 },   "city": "Paris" }
Projection:                      2 projected field(s), _id excluded
Sort:                            sorted by 1 field(s)
Limit:                           10
Translation notes:               $gte on a number; string
Basis:                           SELECT columns FROM one collection, WHERE with AND, ORDER BY and LIMIT; JOIN, GROUP BY, OR, subqueries and functions are refused by name

The rule it applies

SELECT columns FROM one collection becomes db.collection.find(filter, projection) with .sort() and .limit() appended; = maps to a field match, != and <> to $ne, > >= < <= to $gt $gte $lt $lte, IN to $in, LIKE to a regular expression, and conditions joined by AND become sibling keys in one filter document.

Column names, collection names, literal values and the sort direction are carried across unchanged; string literals are retyped with double quotes so the output is valid JavaScript, and the translation notes state what each condition became. Every character is read in your browser: nothing is uploaded and nothing is stored.

A single-table SELECT maps onto a MongoDB find call almost clause for clause: the column list becomes a projection, the WHERE conditions become a filter document, ORDER BY becomes a sort and LIMIT becomes a limit. This page performs that translation for the plain form and refuses the forms it cannot translate honestly.

The rule this page applies: SELECT columns FROM one collection becomes db.collection.find(filter, projection) with .sort() and .limit() appended; = maps to a field match, != and <> to $ne, > >= < <= to $gt $gte $lt $lte, IN to $in, LIKE to a regular expression, and conditions joined by AND become sibling keys in one filter document.

Worked example: "SELECT name, age FROM users WHERE age >= 30 AND city = 'Paris' ORDER BY name ASC LIMIT 10" with the default controls gives the output recorded in the example below, character for character.

How to use the SQL to MongoDB Query Converter

Paste or type the text into the box and press Run. There is nothing to configure: the page reads the text and applies the rule below.

Worked example: with "SELECT name, age FROM users WHERE age >= 30 AND city = 'Paris' ORDER BY name ASC LIMIT 10" the page prints the output in the What to Expect block below, and running it again prints the same bytes.

The rule this page applies

SELECT columns FROM one collection becomes db.collection.find(filter, projection) with .sort() and .limit() appended; = maps to a field match, != and <> to $ne, > >= < <= to $gt $gte $lt $lte, IN to $in, LIKE to a regular expression, and conditions joined by AND become sibling keys in one filter document.

Column names, collection names, literal values and the sort direction are carried across unchanged; string literals are retyped with double quotes so the output is valid JavaScript, and the translation notes state what each condition became.

What to Expect

Best for

  • Moving one report query onto a MongoDB collection
  • Learning how a WHERE clause becomes a filter document

Not ideal for

  • Aggregation pipelines, which need $match and $group stages
  • Queries with OR, joins or subqueries

What this tool keeps

  • Your text, read in this tab and nowhere else
  • The same answer on every run
  • Nothing sent, stored or logged

What may need cleanup

  • Your own wording, which the page never composes for you
  • Spacing carried over from the text you pasted

Common errors

  • JOIN, GROUP BY, HAVING, UNION, DISTINCT, subqueries, window functions, OR, functions in the column list and AS aliases are refused by name rather than dropped, because a translation that silently loses a clause is wrong.
  • An empty box, which the page refuses rather than printing a blank result

Example use cases

  • Prototyping a query by hand
  • Checking a filter document against the SQL it came from

Sample input

SELECT name, age FROM users WHERE age >= 30 AND city = 'Paris' ORDER BY name ASC LIMIT 10

Sample output

MongoDB query: db.users.find({ "age": { "$gte": 30 }, "city": "Paris" }, { "name": 1, "age": 1, "_id": 0 }).sort({ "name": 1 }).limit(10) Collection: users Filter: { "age": { "$gte": 30 }, "city": "Paris" } Projection: 2 projected field(s), _id excluded Sort: sorted by 1 field(s) Limit: 10 Translation notes: $gte on a number; string Basis: SELECT columns FROM one collection, WHERE with AND, ORDER BY and LIMIT; JOIN, GROUP BY, OR, subqueries and functions are refused by name

Who this is for

  • developers
  • data analysts

Frequently asked questions

What rule does this page apply?

SELECT columns FROM one collection becomes db.collection.find(filter, projection) with .sort() and .limit() appended; = maps to a field match, != and <> to $ne, > >= < <= to $gt $gte $lt $lte, IN to $in, LIKE to a regular expression, and conditions joined by AND become sibling keys in one filter document.

What input does it refuse?

JOIN, GROUP BY, HAVING, UNION, DISTINCT, subqueries, window functions, OR, functions in the column list and AS aliases are refused by name rather than dropped, because a translation that silently loses a clause is wrong.

What is left unchanged?

Column names, collection names, literal values and the sort direction are carried across unchanged; string literals are retyped with double quotes so the output is valid JavaScript, and the translation notes state what each condition became.

Is anything uploaded?

No. The text is read by JavaScript in this page and nothing is posted, stored or logged.

Why is JOIN refused instead of approximated?

Because a join needs a second collection and a $lookup stage with its own semantics. Approximating it would produce a query that returns different rows while looking correct, so the page names the clause and stops.

How is a LIKE pattern translated?

Percent signs become .* and underscores become ., the result is anchored when the pattern does not start or end with a wildcard, and every other regex character is escaped, so 'ann%' becomes /^ann.*/.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.