Data & JSON

MongoDB Formatter

Format MongoDB filter and document snippets with ObjectId, ISODate and NumberLong. Preserve constructor notation, minify and copy locally; no query execution.

Content reviewed:

About this tool

Format a MongoDB filter, document or result snippet without losing shell-style BSON constructors. Format adds indentation; Minify removes unnecessary whitespace; Validate checks whether the supported snippet can be parsed.

This is a text formatter for individual values, documents and arrays. It does not connect to MongoDB or run db.collection.find() scripts.

Best use cases

  • Review a filter document before using it in a database client.
  • Make BSON-style result snippets readable while retaining type notation.

How to use it

  1. Paste one document, array or supported value into the input, or use the sample shown on opening the tool.
  2. Choose Format, Minify or Validate. Resolve parser errors before using the output.
  3. Copy the result or download the text file. Run any database operation separately in your own client.

Format shell-style BSON constructors

Input

{_id:ObjectId("507f1f77bcf86cd799439011"),createdAt:ISODate("2026-01-01T00:00:00Z"),total:NumberLong("42")}

Output

{
  _id: ObjectId("507f1f77bcf86cd799439011"),
  createdAt: ISODate("2026-01-01T00:00:00Z"),
  total: NumberLong("42")
}

Format preserves ObjectId, ISODate and NumberLong as constructor expressions. This output is not strict JSON or canonical Extended JSON.

Scope and limits

  • Supports common constructors including ObjectId, ISODate, NumberLong and BinData; it is not a complete mongosh interpreter.
  • Validation checks supported syntax, not database field types, query correctness or BSON value ranges. Use MongoDB's tools to validate database operations.

Data processing

Formatting runs in your browser. No database connection is created and your snippet is not sent to MongoDB. Analytics, if accepted, records operation types rather than snippet content.

FAQ

Can I format a MongoDB query?

Yes, paste the filter document, for example {status: "active"}. Complete query scripts and database execution are outside this formatter's scope.

Why does JSON.parse reject ObjectId(...)?

A constructor call is not a JSON value. MongoDB Extended JSON uses JSON objects to represent BSON types; preserving shell notation here does not convert it to Extended JSON.

Technical references

Related tools

More in this category