MongoDB Query Beautifier

Beautify and indent MongoDB queries and find() statements in your browser.

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

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

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

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

All ArrayKit tools