Internet Toolset

Comprehensive Tools for Webmasters, Developers & Site Optimization

SQL → MongoDB Query Converter

SQL → MongoDB Query Converter

This SQL → MongoDB Query Converter helps you migrate or test SQL SELECT logic in MongoDB by automatically translating:

  • Filter conditions (WHERE → JSON queries with $eq, $gt, $lte, etc.)
  • Logical operators (AND/OR → $and/$or arrays)
  • Set membership (IN (…) → $in)
  • Range queries (BETWEEN … AND … → $gte/$lte)
  • Wildcard patterns (LIKE/ILIKE → $regex)
  • Projection (SELECT col1,col2 → {col1:1,col2:1})
  • Sorting (ORDER BY col ASC|DESC → .sort({col:1|-1}))
  • Pagination (LIMIT/OFFSET → .limit()/.skip())
  • Pretty‑print JSON indent control (0/2/4 spaces)
Filter & Projection

SQL (before):

SELECT name, age FROM users WHERE age >= 18 AND status = 'active';

MongoDB (after):

db.users.find( { "age": { "$gte": 18 }, "status": "active" }, { "name": 1, "age": 1 } );
Logical OR

SQL (before):

SELECT * FROM orders WHERE status = 'shipped' OR total > 100;

MongoDB (after):

db.orders.find( { "$or": [ { "status": "shipped" }, { "total": { "$gt": 100 } } ] } );
IN & Range Queries

SQL (before – IN):

SELECT * FROM products WHERE category IN ('A','B','C');

MongoDB (after – $in):

db.products.find( { "category": { "$in": ["A","B","C"] } } );

SQL (before – BETWEEN):

SELECT * FROM sales WHERE price BETWEEN 10 AND 50;

MongoDB (after – $gte/$lte):

db.sales.find( { "price": { "$gte": 10, "$lte": 50 } } );
Wildcard Matching

SQL (before – LIKE):

SELECT * FROM users WHERE name LIKE 'Jo%';

MongoDB (after – $regex):

db.users.find( { "name": { "$regex": "^Jo.*$" } } );
Sorting & Pagination

SQL (before – ORDER BY):

SELECT * FROM logs ORDER BY timestamp DESC;

MongoDB (after – .sort):

db.logs.find().sort({ "timestamp": -1 });

SQL (before – LIMIT/OFFSET):

SELECT * FROM logs LIMIT 10 OFFSET 20;

MongoDB (after – .limit/.skip):

db.logs.find() .skip(20) .limit(10);
Indent Control

Choose how your JSON is pretty‑printed:

Compact (indent = 0): { "age": { "$gte": 18 }, "status": "active" }
Pretty (indent = 4):
{ "age": { "$gte": 18 }, "status": "active" }