01What is MongoDB Query Builder?
MongoDB queries are just nested objects, but getting the brackets, the method and the stage order right in mongosh takes a few tries. This builder lets you lay the query out as rows and prints the mongosh command for you. Pick a Method: find, aggregate, updateMany, updateOne, deleteMany or insertOne. Type a collection name, then add stage rows. Each row has a type dropdown with $match, $group, $sort, $project, $limit, $skip, $unwind, $lookup, $addFields, $count and $out, plus a box for its body. How the rows are used depends on the method. For find, the first $match becomes the filter and the first $project the projection. The first $sort, $skip and $limit rows turn into chained .sort(), .skip() and .limit() calls, the cursor methods from the MongoDB docs. Other stage types are ignored, and a warning names each ignored row. For aggregate, every row becomes a pipeline stage in the order you listed it. updateOne and updateMany pair the first $match with the Update Document box. deleteMany uses only the filter, and insertOne prints the document box alone. $count, $out and $unwind take a string, so a bare word such as total, archive or $tags is quoted for you. An $unwind path typed without its leading $, like tags, gets one, because MongoDB rejects the path otherwise. Collection names that are not valid JavaScript names, like app-logs, are written as db.getCollection("app-logs") so mongosh can still read them. Here is a small example. Choose find on users, then add $match { age: { $gte: 18 } }, $project { "name": 1, "_id": 0 }, $skip 20 and $limit 10. You get db.users.find with the filter and projection, followed by .skip(20) and .limit(10). Bodies are copied exactly as you typed them, so mongosh-style unquoted keys stay unquoted. The tool still tries to parse each one and warns when it cannot, which usually means a missing brace or quote. It also catches two mistakes the server rejects. One is an update document with no operators like $set, which needs replaceOne instead. The other is an insertOne document whose top-level keys start with $. Some limits to keep in mind. It does not check operator names, field names or whether a stage is valid in that position. The query is assembled in the page from your rows. It never connects to a database or runs anything, so try it on a dev copy before you point it at production.
Backend developers and analysts who write MongoDB queries in mongosh or Compass and want the method, filter and pipeline shape right first time. The tool runs entirely in your browser, so your data never leaves your device.
02How to use MongoDB Query Builder
- Select a Method and type the Collection name.
- Add stage rows with the plus button and pick each row's stage type.
- Type the body for each stage. For updates or inserts, fill in the Update Document box too.
- Read any warnings under the output. They name ignored rows and bodies that could not be parsed.
- Copy the MongoDB Query and run it in mongosh or Compass.
03Worked examples
- Input:
Method find, collection users, $match { "age": { "$gte": 18 } }, $sort { "name": 1 }, $limit 10 - Result:
db.users.find( { "age": { "$gte": 18 } } ) .sort({ "name": 1 }) .limit(10); - For find, the $match stage becomes the filter and $sort/$limit become chained cursor methods.
- Input:
Method aggregate, collection orders, $match { "status": "completed" }, $count done - Result:
db.orders.aggregate([ { "$match": { "status": "completed" } }, { "$count": "done" } ]); - A bare word typed for $count is quoted for you.
- Input:
Method updateMany, collection products, $match { "stock": 0 }, update { "$set": { "available": false } } - Result:
db.products.updateMany( { "stock": 0 }, { "$set": { "available": false } } ); - Input:
Method deleteMany, collection app-logs, no stages - Result:
db.getCollection("app-logs").deleteMany( {} ); - A name with a hyphen isn't valid after db., so getCollection() is used; an empty filter deletes every document.
- Input:
Method find, collection users, $match { age: { $gte: 18 } }, $project { "name": 1, "_id": 0 }, $skip 20, $limit 10 - Result:
db.users.find( { age: { $gte: 18 } }, { "name": 1, "_id": 0 } ) .skip(20) .limit(10); - Unquoted mongosh keys are kept as typed. $project becomes the second argument.
- Input:
Method updateOne, collection users, $match { "_id": 1 }, update { "name": "Ann" } - Result:
db.users.updateOne( { "_id": 1 }, { "name": "Ann" } ); updateOne/updateMany need update operators such as $set or $inc; a plain document is rejected (use replaceOne to replace a whole document). - The query is still printed. The last line is the warning text shown under the output. Wrap the field in $set to fix it.
04Common use cases
- Drafting an aggregation that groups completed orders by customer and sums the totals for a sales report.
- Writing an updateMany that sets a new field on every existing product, after checking the filter with find.
- Showing a team the difference between a find filter and a $match stage in a pipeline.
- Preparing a $lookup join between orders and users to paste into MongoDB Compass or mongosh.
- Counting tag usage with $unwind, $group and $sort without fighting nested brackets.
- Building a deleteMany to clear test documents from a dev database, with the filter reviewed first.
05Tips
- Put $match first in a pipeline so it can use an index and shrink the data before $group or $lookup.
- Before an updateMany or deleteMany, switch the Method to find with the same $match and check what comes back.
- An empty filter on deleteMany prints {} and removes every document in the collection.
- Inside $group, field paths are quoted values with a $ prefix, like "$amount", while operators like $sum are keys.
- For find, use only one row of each type. Only the first $match or $sort counts, and the warning names any extra row.
06Related concepts
Aggregation pipeline, mongosh, $lookup, Query filter, MongoDB indexes.
Frequently Asked Questions
What is MongoDB Query Builder?
MongoDB Query Builder is a free, browser-based developer tool on AIDToolStack. Visual MongoDB query/aggregation builder It requires no installation or sign-up and works entirely in your browser.
Is MongoDB Query Builder free to use?
Yes. No sign-up, no fees and no usage cap.
Does MongoDB Query Builder store my data?
No. It runs in your browser; nothing is uploaded.