JSON Toolkit

Fast, private JSON tools that run in your browser.

πŸ”’ Data stays in your browser

MongoDB Query Generator

Build mongosh commands from JSON without having to remember the syntax. Choose an operation, add a filter, update or pipeline, and get a formatted command to paste into mongosh or MongoDB Compass. Commands are only generated as text; nothing connects to a database.

MongoDB Query Generator

Build mongosh commands from JSON. Commands are generated as text in your browser and are never run against a database. Extended JSON such as {"$oid": …} and {"$date": …} becomes ObjectId(…) and ISODate(…).

How to use the MongoDB Query Generator

  1. Enter the collection name and choose an operation, such as find or aggregate.
  2. Fill in the JSON fields that operation needs, like a filter, an update or a pipeline.
  3. Click Generate Command and copy the result into mongosh.

Features

  • 13 operations, including find, aggregate, updateMany, replaceOne and createIndex
  • Extended JSON from Compass and mongoexport becomes ObjectId(…) and ISODate(…)
  • Plain fields in an update are wrapped in $set automatically
  • Warnings for risky commands, such as deleteMany with an empty filter
  • Aggregation pipelines are checked for misspelled stages
  • Test the command on sample documents in your browser before running it on a real database
  • Ready-to-use Node.js (mongodb driver) and Python (pymongo) code
  • A plain-English explanation, plus suggested indexes that follow MongoDB's Equality, Sort, Range rule
  • Every value is escaped, so pasted data cannot change the command

Frequently asked questions

Does this connect to my database?
No. It only produces text for you to copy. The Test on sample data feature runs the command on documents you paste, using a MongoDB engine inside your browser; nothing is sent anywhere.
Can I paste documents exported from Compass?
Yes. Extended JSON such as {"$oid": "…"} and {"$date": "…"} is converted to ObjectId("…") and ISODate("…").
Why was $set added to my update?
MongoDB rejects updates that are plain documents. Wrapping the fields in $set gives the result you most likely intended, and the generator tells you when it does this.

Related tools