MongoDB Query Beautifier Online

Beautify and indent MongoDB queries and find() statements in your browser. Your queries stay on your device.

This tool runs entirely in your browser. The MongoDB queries you paste never leave your device and nothing is uploaded to ArrayKit.

Built and maintained by Udit Agarwal

Beautify an aggregation pipeline

About MongoDB Query Beautifier

This MongoDB query beautifier turns dense, one-line MongoDB shell queries into readable, properly indented code. Paste a cramped db.collection.find() call, a bare filter object, or a chained statement with sort, limit, and projection, and it pretty-prints the result with consistent spacing and clean line breaks. It is built for backend developers, database engineers, and QA testers who copy queries out of application logs, Compass, or chat threads and need to read, debug, or share them fast. The request is built and formatted entirely in your browser using Prettier, so there is no setup and no waiting on a server round-trip. Operators like $gte, $in, and $regex are preserved exactly as written, and the formatted output updates live as you paste or edit. When you are done, copy the result or download it as a .js file.

Features

  • Beautifies db.collection.find() and other chained shell statements
  • Indents bare filter objects and arrays, not just full queries
  • Preserves operators like $gte, $in, $regex and $or exactly as written
  • Keeps chained methods such as sort(), limit() and projection readable
  • Pretty-prints with Prettier for consistent spacing and quoting
  • Formats live as you type or paste — no Run button needed
  • Copy the beautified query or download it as query.js
  • Runs entirely in your browser with nothing uploaded

How to use the MongoDB Query Beautifier

  1. Paste your MongoDB query or find() statement into the input box.
  2. Read the beautified, indented query in the output panel as it updates live.
  3. Fix any reported syntax error, such as an unbalanced bracket.
  4. Copy the result or use Download to save it as query.js.

Example

Input

db.users.find({status:"active",age:{$gte:18}},{name:1,_id:0}).sort({createdAt:-1}).limit(20)

Output

db.users
  .find({ status: "active", age: { $gte: 18 } }, { name: 1, _id: 0 })
  .sort({ createdAt: -1 })
  .limit(20);

A cramped find() call is indented into readable shell code.

Common errors & troubleshooting

  • Could not format — unbalanced brackets or parentheses. — Check that every {, [ and ( has a matching close; paste the full statement, not a truncated snippet.
  • A trailing comma or missing comma breaks parsing. — Remove the stray comma or add the missing one between fields, then the query reformats automatically.
  • Pasting an aggregation pipeline instead of a query. — Use the MongoDB Aggregation Beautifier for db.collection.aggregate([...]) pipelines.
  • Unquoted keys with special characters fail to format. — Wrap keys that contain dots or hyphens in double quotes, e.g. "address.city".

Frequently asked questions

What is a MongoDB query beautifier?
It is a tool that takes a compact, hard-to-read MongoDB shell query and reformats it with proper indentation, spacing, and line breaks so you can read and debug it. This one handles db.collection.find() calls, filter objects, and chained methods like sort and limit.
Does it change what my query does?
No. It only changes whitespace, indentation, and quoting style. The fields, operators, and values stay exactly the same, so the beautified query behaves identically to the original.
Can it beautify aggregation pipelines too?
This tool is tuned for find() queries and filter objects. For db.collection.aggregate([...]) pipelines with stages like $match and $group, use the MongoDB Aggregation Beautifier.
Is my query data private and safe to paste here?
Yes. The beautifier runs entirely in your browser using Prettier. The queries you paste never leave your device and nothing is uploaded to ArrayKit, so it is safe to format queries that contain sensitive field names or values.
What indentation does it use?
Output is indented with 2 spaces and consistent operator spacing for clean, predictable formatting that is easy to read and diff.
Why does it say it could not format my query?
That usually means the input has a syntax problem, such as an unbalanced bracket, a stray comma, or a truncated copy. Paste the complete statement and fix any mismatched brackets, and it will reformat automatically.

Related tools

  • MongoDB Aggregation Beautifier — Beautify and indent MongoDB aggregation pipelines in your browser.
  • MongoDB Query Formatter — Format MongoDB shell queries and aggregation pipelines.
  • MongoDB Explorer — Explore a MongoDB document or collection sample and infer its field schema and types.
  • SQL Formatter — Format SQL for MySQL, PostgreSQL, SQL Server, SQLite, BigQuery and Oracle.
  • JSON Formatter — Beautify, minify and validate JSON with error locations.
  • JS / TS Formatter — Beautify JavaScript, TypeScript and JSX/TSX with Prettier options, or minify plain JavaScript.
  • GraphQL Formatter — Format or minify GraphQL queries and schemas, validate syntax and extract operations.

Guides

More Code Formatters tools

  • MongoDB Aggregation Beautifier — Beautify and indent MongoDB aggregation pipelines in your browser.
  • MongoDB Explorer — Explore a MongoDB document or collection sample and infer its field schema and types.
  • OpenAPI / Swagger Formatter — Format and validate OpenAPI / Swagger specs (JSON or YAML) and count paths and operations.
  • CSS Unit Converter — Convert between px, rem, em, pt and % live with a configurable root font size.
  • Glob to Regex — Convert a glob or wildcard pattern into an equivalent JavaScript regex.
  • HTML to Markdown — Paste HTML and convert it to clean Markdown live, with GFM tables, lists and code blocks.
  • TOML Formatter & Converter — Format and validate TOML, and convert TOML ↔ JSON.
  • logfmt to JSON — Convert logfmt key=value logs to JSON and back.
  • dotenv to JSON — Convert a .env file to JSON and JSON back to .env, with quoting and comments handled.
  • CSV to Markdown Table — Convert CSV or TSV data into a Markdown table, with alignment and header options.
  • INI to JSON — Convert INI config files to JSON and JSON back to INI, with sections and comments.
  • Markdown Table Generator — Build a table in an editable grid and export Markdown, HTML, AsciiDoc and LaTeX.

See all Code Formatters tools (32) · All tools