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

Doing Multiple MongoDB Exports At Once With Studio 3T #Studio3T_AMA

Posted on: 04/08/2021 (last updated: 21/04/2022) by DJ Walker-Morgan

Q: Now my boss wants three different spreadsheets generated at the same time? Can I do this without creating a tangle of scheduling?

Welcome to the latest Studio 3T Ask Manatees Anything – #Studio3T_AMA. Want to know how to use Studio 3T to make your MongoDB life better? Just tweet and use #Studio3T_AMA or email [email protected].

A: Yes you can. In the previous Ask Manatees Anything, we showed you how to turn an export into a scheduled Task. What we didn’t mention was that Tasks are actually containers for multiple similar operations.

Diving into a Task

An Export Task can contain as many Exports as you need. That first Export Task we created also created an Export unit within the task. Let’s have a look at that. Bring up the Tasks view by clicking Tasks in the global toolbar.

A Simple Single Task in the Task view

Select your spreadsheet exporting task and click on Edit. Now you can see an overview of the Export:

The Export View shows the Export units configuration

It contains one unit, the export we created previously to export the spreadsheet. In this view, you can see where the data is being sourced – from a local MongoDB instance, in a db called samples and a collection called Customers, what kind of source (the entire collection), where the data will be written (to a local file) and in what format (CSV).

The Add Unit button allows a new export unit to be included in the Task

Adding a Unit for Export

If we want to do another export, we just add a unit to this list. Click Add Unit and as we’re in an Export Task, we’ll be prompted for where the data we want to export is:
Here we select an aggregation query as the source of data for the export

For this example, we’re going to do a quick aggregation query on the data. The boss wants total customers per state as a separate report, the kind of thing aggregation was built to do. Let’s click Next and see:

The query is going to be applied to a database and collection

We have to select which collection is going to be the basis for this aggregation; most of the time, Studio 3T can figure it out from where you are in the UI. Once we’ve done that, we get to pick which kind of export to do.

Selecting the Export Format

And we select CSV because we want to import this into a spreadsheet. Now we can click Configure.

Making an Aggregation and Configuring an Export

We are now ready to Configure both our aggregation query and export at the same time.

Above, the Aggregation Editor. Below, the Export Configuration.

This view of the Export Source pane is scrollable; yes there is more to see. At the top is the definition of the Export source and as we are using an aggregation, underneath that is a view of the aggregation we want to use. Underneath all of that is the export field selector and CSV controls.

Now, if you recall from a previous AMA, Studio 3T scans the source to work out which fields are going to be available. And it notes that in a little “scan finished” panel in the bottom right. That scan has looked at what we currently have coming out of the aggregation.

Ok, time to make some data and edit our aggregation. Click on Open Editor and you’ll find yourself in the Aggregation editor, with a $match stage already in place. That’s been put there to let some data flow through up front.

The initial Aggregation Pipeline already has a $match operator in it

Now we want to count all the customers in each state. The $group stage specialises in grouping things and doing calculations as it does it. So in the editor window, let’s start with:

{
_id: "$address.state",

This says the output should have a unique _id field derived from the address.state field. That also implies that the output should be grouped by that field.

    customer_count: { $sum: 1 }
}

So as each record comes in and is grouped by state, this field, customer_count, gets 1 added to it. And so we count how many matching documents for that state there are.

Our $group aggregation being edited and tested in the Stage Input/Output views

You can test all that out in the aggregation editor’s previews of input and output. When you are happy, click on Save Changes to go back to the Export view.

Dealing with Changeable Sources

It’ll look exactly the same apart from one addition:

The source query has changed and that brings up this message

If you didn’t dismiss the Scan dialog earlier, use that to launch a scan. If you did, and who could blame you, head to Change Source in the upper part of the view, click on the down arrow next to it to reveal a menu and a Rescan Source button which will start a fresh scan.

Where the Rescan Source Menu Item can be found
Where the Rescan Source Menu Item can be found

And when that’s done, you’ll see this:

The Aggregation is complete and the Scanned Fields now match what comes out of the query

The aggregation is now showing in the fields; _id is standing in for state – you can use $project to turn that into a state field if you want.  Don’t forget to set the CSV format to Excel. Check the output in the Output Preview, and then set the Export Target to where you want the resulting file to be output.

Click on Save Task to save the whole Task, including the new unit, and then click on the Export Overview tab to reveal both units.

Ready to Run

Clicking on the Run button will run both units sequentially and you can see their progress in the Operations panel. You can use the Task Scheduler to run this Task by selected day, time or have it an arbitrary calendar.

There’s no limit to the number of units a Task can hold so you can bundle up your export chores into one easy to orchestrate operation. Enjoy your new found exporting powers.


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

DJ Walker-Morgan

Dj has been around since Commodore had Pets and Apples grew everywhere. With a background in Unix and development, he's been around the technology business writing code or writing content ever since.

Related articles

  • What’s New in Studio 3T 2021.3 | Data Masking on Exports and Our Darkest Theme Yet
  • Lesson 4, Exercise 1: Using IntelliShell to query single and multiple values in an array
  • Lesson 4, Exercise 3: Using Visual Query Builder to query multiple array values
  • How do I use MongoDB regex (regular expressions) in Studio 3T? #Studio3T_AMA
  • How do you make Studio 3T export MongoDB collections to unique files? #Studio3T_AMA

Tags

academy aggregation AMA atlas community connections date tags export features hackolade import intellishell JSON knowledge base migration modelling mongodb mongoodb productivity query regex releases schema security SQL Studio 3T tasks tips updates webinar windows

Browse by MongoDB topic

  • Connecting to MongoDB
  • Database Administration & Security
  • Getting Started with MongoDB
  • Getting Started with Studio 3T
  • Import/Export
  • Job Automation & Scheduling
  • MongoDB Aggregation Framework
  • MongoDB/Studio 3T Workshops
  • Performance
  • Query & CRUD Operations
  • Schema
  • Studio 3T Licensing
  • Support and other resources
  • Working with MongoDB & SQL
  • Working with MongoDB Atlas

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