Skip to content
Studio 3T - The professional GUI, IDE and client for MongoDB
  • Tools
    • Aggregation Editor
    • IntelliShell
    • Visual Query Builder
    • Export Wizard
    • Import Wizard
    • Query Code
    • SQL Query
    • Connect
    • Schema Explorer
    • Compare
    • SQL ⇔ MongoDB Migration
    • Data Masking
    • Task Scheduler
    • Reschema
    • More Tools and Features
  • Solutions
  • Resources
    • Knowledge Base
    • MongoDB Tutorials & Courses
    • Tool/Feature Documentation
    • Reports
    • Case Studies
    • Whitepapers
    • Blog
    • Testimonials
    • Community
  • Contact us
    • Contact
    • Sales Support
    • Feedback and Support
    • Career
    • About Us
  • Store
    • Buy Now
    • Preferred Resellers
    • Team Pricing
  • My License
  • Download
search

Studio 3T Knowledge Base

  • Documentation
  • Tutorials
  • Workshops
Take the fastest route to learning MongoDB. Cover the basics in two hours with MongoDB 101, no registration required.
Start the free course

3 Best MongoDB Aggregation Pipeline Builders

Posted on: 28/10/2020 (last updated: 09/03/2022) by Sruthi Varanasi

When you start with MongoDB, the find() command for querying data will probably be sufficient, but as soon as you start doing anything more advanced than data retrieval, you will need to know more about the MongoDB aggregation pipeline.

The MongoDB aggregation pipeline consists of stages. Each stage transforms the documents as they pass through the pipeline.

Here’s an example of a simple, typical MongoDB aggregation pipeline which uses four common aggregation stages:

  • $match() – filters those documents we need to work with, those that fit our needs
  • $group() – does the aggregation job
  • $sort() – sorts the resulting documents the way we require (ascending or descending)
  • $project() – to return only those fields you need so as to avoid processing more data than is necessary

Common uses for aggregation include:

  • Grouping data by a given expression
  • Calculating results based on multiple fields and storing those results in a new field
  • Filtering data to return a subset that matches the given criteria
  • Sorting data

There are a myriad of MongoDB tools available, offering features like schema visualization, code auto-completion, data import/export, and so on – but only a few offer a dedicated MongoDB aggregation feature.

To help you make filtering, transforming, sorting, computing, and aggregating your data easier, here are three MongoDB aggregation tools you can use.

MongoDB Aggregation Editor in Studio 3T

Studio 3T introduced the Aggregation Editor in 2015, becoming the first GUI (other than MongoDB Compass) to enable its users to build accurate aggregation queries.

It also made debugging easier by defining stage operators and checking inputs and outputs at each stage.

Its editor has since then been made better by adding support for additional aggregation stages, giving an option to copy and paste aggregation stages, the ability to export results to another collection, CSV, JSON, SQL, or mongodump, and disable pipeline stages temporarily, and many more.

“Studio 3T is the tops for me. In only 30 minutes, I can gain one whole day of work when building aggregation queries.”

– Pierre Yves Folens, DevOps Engineer at Orange

You can break down a complex query into easier stages. In each of these stages, you complete a different operation on the data. This approach allows you to check whether your query is functioning properly at every stage by examining both its input and output.

There is no limit to the number of stages used in the query, or how you combine them.

Source: Aggregation Editor in Studio 3T

You can see all your aggregation stages at a glance and add, edit, duplicate, and move as needed in the Pipeline tab. You can also view each stage in your pipeline individually, where you can edit and analyze your input and output stages individually.

Studio 3T’s aggregation editor also lets you translate your aggregation query to JavaScript (Node.js), Java (2.x, and 3.x driver API), Python, C#, PHP, Ruby, and the mongo shell language.

Download Studio 3T here.

Aggregation Pipeline Builder in MongoDB Compass

MongoDB Compass is the GUI tool for MongoDB to visualize and query data, and they added a MongoDB aggregation pipeline builder to it in 2018. The aggregation pipeline builder provides the ability to create aggregations in a simple and real-time manner.

MongoDB Aggregation Pipeline builder in Compass

Source: MongoDB

As you select different aggregation stages to execute from drop-down boxes on the left side of the screen, the results of those actions are shown on the right side of the screen. You can add as many stages as you want, and save or clone pipelines as needed.

When you are done building a pipeline, you can copy it to the clipboard. The resulting JSON code can then be executed against the MongoDB database using the shell environment.

You can use the Aggregation Pipeline Builder to export your finished pipeline to only some of the few supported languages though: Java, Node, C#, and Python 3, unlike the wider range of options available with other tools.

Download MongoDB Compass here.

The mongo Shell

The most basic way to access MongoDB is through the mongo Shell, an interactive JavaScript interface to MongoDB. You can use it to query, update data, and complete admin tasks.

Aggregation in Mongo Shell

Source: MongoDB

It’s included in the MongoDB server installation, so you’re all set as long as you’re comfortable with shell commands.

While you can certainly use the mongo Shell to build your aggregation queries, traversing objects and writing long queries in the command line can get annoying fast, so using the shell is usually best for quick peeks or admin tasks.

To create an aggregation pipeline in the mongo Shell, you can use the following syntax:

db..aggregate([
  {
    <$stage1>
  },
  {
    <$stage2>
  }
  ...
])

MongoDB provides the db.collection.aggregate() method in the mongo Shell and the aggregate command to run the aggregation pipeline. The mongo Shell outputs the results directly to the terminal.

Download the mongo shell as bundled by default with a MongoDB server installation here, or as a stand-alone here.

The MongoDB aggregation pipeline is an incredibly powerful framework for analyzing and abstracting data. While writing aggregation queries can get tricky, there are tools to help make building and debugging your pipeline in a matter of minutes instead of days.


How helpful was this article?
This article was hideous
This article was bad
This article was ok
This article was good
This article was great
Thank you for your feedback!

About The Author

Sruthi Varanasi

A vivid marketer having the zeal to explore new Marketing and Growth Hacks for businesses and SaaS products! If not doing this, you can see me listening to music and toiling around Indian restaurants in Berlin.

Article navigation

Related articles

  • Best MongoDB University Alternatives
  • 5 Best Tools for MongoDB Atlas in 2021
  • 9 Best MongoDB Tutorials & Courses (Free & Paid)
  • Best MongoDB Tools (Updated: April 2021)
  • MongoDB Database Testing: A Detailed Walkthrough of Best Practices

Studio 3T

MongoDB Enterprise Certified Technology PartnerSince 2014, 3T has been helping thousands of MongoDB developers and administrators with their everyday jobs by providing the finest MongoDB tools on the market. We guarantee the best compatibility with current and legacy releases of MongoDB, continue to deliver new features with every new software release, and provide high quality support.

Find us on FacebookFind us on TwitterFind us on YouTubeFind us on LinkedIn

Education

  • Free MongoDB Tutorials
  • Connect to MongoDB
  • Connect to MongoDB Atlas
  • Import Data to MongoDB
  • Export MongoDB Data
  • Build Aggregation Queries
  • Query MongoDB with SQL
  • Migrate from SQL to MongoDB

Resources

  • Feedback and Support
  • Sales Support
  • Knowledge Base
  • FAQ
  • Reports
  • Case Studies
  • White Papers
  • Testimonials
  • Discounts

Company

  • About Us
  • Blog
  • Careers
  • Legal
  • Press
  • Privacy Policy
  • EULA

© 2022 3T Software Labs GmbH. All rights reserved.

  • Privacy Policy
  • Cookie settings
  • Impressum
When you click "Accept", you are agreeing to cookies being on your device. They may improve site navigation, site usage analysis, or the relevance of messages. It is up to you which cookies are enabled. Read our Privacy Policy.
Manage cookies
Accept
✕

Privacy Preference Center

A cookie is a small file of letters and numbers that is downloaded on to your computer when you visit a website. Cookies are used by many websites and can do a number of things, eg remembering your preferences, recording what you have put in your shopping basket, and counting the number of people looking at a website. In the form below you can choose which cookies, except for essential cookies, to allow or disable.

Accept all cookies

Manage consent preferences

Essential cookies are strictly necessary to provide an online service such as our website or a service on our website which you have requested. The website or service will not work without them.

Performance cookies allow us to collect information such as number of visits and sources of traffic. This information is used in aggregate form to help us understand how our websites are being used, allowing us to improve both our website’s performance and your experience.

Functional cookies collect information about your preferences and choices and make using the website a lot easier and more relevant. Without these cookies, some of the site functionality may not work as intended.

Social media cookies are cookies used to share user behaviour information with a third-party social media platform. They may consequently effect how social media sites present you with information in the future.

Accept selected