tools

SQL to MongoDB converter

Paste a WHERE clause, or a whole SELECT, and get the MongoDB filter document that matches the same rows.

  • free
  • no sign-up
  • runs in your browser
  • MIT
input · SQL
output · MongoDB filter
6 rules · 6 fields · converted Runs in your browser: nothing leaves it.

How it converts

The WHERE clause is parsed into qnot's query tree, then written out with the mongo codec. Comparisons map to $eq, $ne, $lt, $gte; IN and NOT IN to $in and $nin; BETWEEN to a $gte/$lte pair; IS NULL to null.

LIKE patterns become anchored, escaped regular expressions: a leading and trailing % is contains, a trailing % starts-with, a leading % ends-with. Patterns with _ or an inner % are refused rather than guessed.

Dates stay ISO strings. If your collection stores BSON dates, wrap them with new Date() in your app, or declare the field as f.date() and convert in one place.

Use it in your app

follows your input and settings

The converter is qnot's codecs. Declare the fields once and the same two calls run on your server or in the browser, typed end to end.

Questions

Is my query sent anywhere?
No. The converter is qnot running in your browser: parsing, schema inference and conversion all happen on this page, and nothing you paste leaves your browser.
Which SQL does it understand?
WHERE conditions: comparisons, IN, BETWEEN, LIKE/ILIKE, IS [NOT] NULL, AND, OR, NOT and parentheses, with quoted identifiers and string, number and boolean literals. Joins, subqueries and placeholders like $1 are not part of a filter and are refused with an error.
Why does it show a schema?
qnot's codecs are typed by a schema. The tool infers a permissive one from your input (numbers, booleans, dates, lists, nested arrays), so you can paste any query. In your app you declare the fields once with defineFields and get the same conversion with exact types.