·9 min read

How to Build a MongoDB Aggregation Pipeline Without Writing a Single Line of Code

Aggregation pipelines are one of the most powerful features in MongoDB. They're also one of the most frustrating things to write from scratch. A visual pipeline builder lets you add stages one at a time, see the output at each step, and drag to reorder — no raw JSON required.

A single MongoDB aggregation pipeline can span 50 lines of JSON, and debugging a broken stage usually means running the whole thing and guessing where it went wrong. There's a better way. This tutorial walks through exactly how to build pipelines visually using Mongon, a native macOS MongoDB client built in Swift.

Why Aggregation Pipelines Are So Hard to Write

The syntax isn't the hard part. The hard part is reasoning about a multi-stage pipeline as a single block of text.

You write $match, then $lookup, then $group, then $project. By the time you get to stage four, you've forgotten what the documents look like after stage two. You run the pipeline, get an unexpected result, and now you're commenting out stages one by one to find the problem.

This is the standard workflow for most MongoDB developers. It works. It's just slow and annoying.

A visual builder solves this by making each stage independent and immediately testable. You see the output before adding the next stage. Problems surface early, not at the end.

What a Visual Pipeline Builder Actually Does

A good visual MongoDB aggregation tool does three things:

  1. Lets you add stages individually from a list of supported operators
  2. Shows you the output of each stage before you move on
  3. Lets you reorder stages without manually cutting and pasting JSON

Mongon's pipeline builder covers all three. It supports all 14 aggregation pipeline stages, shows a live preview per stage, and lets you drag stages into any order. The final pipeline can be exported as raw MongoDB query syntax when you need it.

Building Your First Pipeline in Mongon

Here's a practical walkthrough. Say you have an orders collection and you want to find the total revenue per customer for orders placed in the last 30 days, sorted by highest value.

Step 1: Open the Pipeline Builder

Open Mongon, connect to your database, and navigate to the orders collection. Select the Aggregation tab. You'll see an empty pipeline canvas with an option to add your first stage.

No blank JSON file. No boilerplate. Just a clean starting point.

Step 2: Add Your First Stage

Click "Add Stage" and choose $match from the dropdown. A structured input form appears for that stage type.

For this example, you want to filter orders from the last 30 days. Instead of writing { "createdAt": { "$gte": ISODate("2026-03-22T00:00:00Z") } } by hand, you can use one of Mongon's 35+ date macros directly in the stage input. Type #last30days and it resolves automatically. No manual ISODate construction required.

Add a second condition to match only completed orders: { "status": "completed" }. Your $match stage is done.

Step 3: Preview Results at Each Stage

This is where the visual builder pays off. Before adding another stage, Mongon shows you the actual documents that pass through $match. You can verify the date filter is working and that only completed orders are coming through.

If something looks wrong, you fix it here. Not after you've built four more stages on top of a broken filter.

Step 4: Add More Stages and Reorder Them

Add a $group stage next. Group by customerId and sum the totalAmount field:

_id: "$customerId"
totalRevenue: { $sum: "$totalAmount" }

Mongon's form guides the structure. You pick the accumulator from a dropdown rather than remembering the exact operator syntax. Preview the output. You'll see one document per customer with their aggregated revenue.

Add a $sort stage. Sort by totalRevenue descending. Preview again. The top customers appear first.

Add a $lookup stage to join against your customers collection and pull in customer names. Then add $project to shape the final output.

At any point, you can drag a stage up or down to change its position in the pipeline. If you decide the $project should come before the $sort, drag it there. The preview updates immediately.

Step 5: Export the Final Pipeline

When the pipeline looks right, export it. Mongon outputs the complete aggregation query as valid MongoDB syntax, ready to paste into your application code, a migration script, or a mongosh session.

You built a five-stage pipeline. You saw the output at every step. You never wrote a full pipeline from scratch.

The 14 Aggregation Stages Mongon Supports

Mongon covers all 14 aggregation pipeline stages in its visual builder:

StageWhat It Does
$matchFilters documents by condition
$groupGroups documents and applies accumulators
$projectReshapes documents, includes/excludes fields
$sortOrders documents by one or more fields
$limitCaps the number of output documents
$skipSkips a number of documents
$lookupJoins documents from another collection
$unwindDeconstructs an array field into separate documents
$addFieldsAdds computed fields to documents
$replaceRootReplaces the root document with a specified field
$countCounts documents in the pipeline
$facetRuns multiple sub-pipelines in parallel
$bucketGroups documents into ranges
$outWrites pipeline results to a collection

Every stage has a structured input form. You don't need to memorize operator syntax to use any of them.

Using Date Macros Inside Your Pipeline

Date-based filtering is one of the most common things you'll do in an aggregation pipeline. It's also one of the most tedious to write correctly.

Mongon includes 35+ date macros that work across all pipeline stages. Instead of calculating and formatting ISO dates manually, you use readable shorthand:

  • #today resolves to the start of today
  • #last7days resolves to 7 days ago from now
  • #startOfMonth resolves to the first moment of the current month
  • #last30days, #last90days, #startOfYear, and more

These work in $match conditions, $addFields expressions, and anywhere else you'd use a date value. The macro resolves at query time, so your pipeline stays current without editing.

This is particularly useful for saved pipelines you run regularly. Build it once with #last7days, save it, and run it every week without touching the query.

When You Still Want to Write Code

The visual builder handles most pipeline work well. But there are cases where writing raw JSON is faster, especially if you already know exactly what you want and the pipeline is short.

Mongon doesn't force you to choose. You can switch between the visual builder and a raw editor within the same pipeline. Build visually, inspect the generated JSON, tweak a specific expression by hand if needed, then go back to the visual view.

The two modes coexist. You use whichever is faster for the task in front of you.

If you're working with MongoDB on a Mac and aggregation pipelines are a regular part of your workflow, the visual builder alone is worth trying Mongon. No Electron overhead, no 4-second startup, no hunting through menus. Open it, build the pipeline, see the results.

FAQs

What is a MongoDB aggregation pipeline builder GUI?

It's a visual tool that lets you construct MongoDB aggregation pipelines by adding and configuring stages through a graphical interface rather than writing raw JSON. You can preview the output at each stage and reorder stages by dragging them.

Does Mongon support all MongoDB aggregation stages?

Yes. Mongon's visual pipeline builder supports all 14 aggregation pipeline stages, including $match, $group, $lookup, $unwind, $facet, $bucket, and $out, among others.

Can I use date filters in the visual pipeline builder?

Yes. Mongon includes 35+ date macros like #today, #last7days, and #startOfMonth that work inside any pipeline stage. They resolve automatically at query time, so you don't need to construct ISODate values manually.

Can I export the pipeline I build visually?

Yes. Once your pipeline is ready, Mongon exports it as valid MongoDB aggregation syntax. You can paste it directly into application code, a migration script, or mongosh.

How is Mongon's pipeline builder different from MongoDB Compass?

Compass also has a pipeline builder, but it runs on Electron and carries the performance overhead that comes with it. Mongon is built natively in Swift for macOS, starts instantly, and uses significantly less memory. The stage-by-stage preview and date macro support are also specific to Mongon. See our full Mongon vs Compass comparison.

Do I need to know MongoDB aggregation syntax to use the visual builder?

No. The visual builder guides you through each stage with structured input forms and operator dropdowns. That said, understanding what each stage does will help you build more effective pipelines. The builder is useful for both beginners learning aggregation and experienced developers who want to move faster.

Is the aggregation pipeline builder available in the free version of Mongon?

Yes. The visual aggregation pipeline builder is part of Mongon's core features, available with the free plan alongside up to 3 connections.

Related Articles

Try the pipeline builderFree on the Mac App Store