Regularly Exporting MongoDB Data #Studio3T_AMA
Q: Now I can create the data for spreadsheets using Studio 3T, my boss wants me to do that every day for their reports. What can I do to save time?
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: Tasks are the key to repeatability in Studio 3T. Tasks are operations in Studio 3T that can be saved and re-run. Saved operations are called Tasks and if you followed our previous Studio 3T AMA posting, you may be surprised to learn you’ve already done most of the work to create one.
Let’s just go back to the screen where you configure an Export:
We previously used this panel to configure which fields are included, or excluded, from the export process, and control the formatting and destination of the output. When ready, you could press the Run button at the top, to kick the export off manually.
Wait though, and check out the other buttons at the top of the pane. Save Task will take this configuration and let you save it as a named task. Click that and name your task “Export Spreadsheet”. If you’ve previously done that, you can Save Task As to give it a new name. Whichever you do, when the task has successfully saved, you’ll be given an option to open the Tasks Viewer.
The Tasks Viewer is a window on all the saved tasks. The another way to get there is to go to the global toolbar and where you can click this Tasks button:
You’ll see something like this view below if you only have one Task and have selected it:
Tasks can be saved from Imports, Exports, Data Masking, Data Compare and Sync, Reschema, and SQL Migrations – they are all built as Tasks and managed from the viewer. We can talk about that some other time.
Right now, we want to export that CSV file. To re-run a Task on demand, select it in the Task viewer and click on the Run button. That’s it. A confirmation dialog will pop up (you can tell it not to in future by selecting the checkbox on the bottom right). Once you’ve ok’d that, your export will run, and deposit the exported data in the file you previously selected. You can now re-run the spreadsheet import and you are good to go.
If you want to run this export task regularly, check out the Schedule button. This lets you regularly run tasks at set times or on particular days of the week. Your scheduling options include running it once at a set time in the future:
Running it every day at a particular time:
Or, most usefully, you can create an ad-hoc schedule which can be based on days of the months or days of the week or both:
You’ll need to keep your copy of Studio 3T running for the Scheduler to fire off the exports. It’s still a lot easier than remembering to open Tasks, select the task and select Run every day. With the MongoDB data export automated, the only thing left is converting it into your spreadsheet’s own format. Excel’s own macros can be used to automate that or you can deploy one of the many command line utilities available.
With Studio 3T you can be automatically exporting your CSV files to feed spreadsheets every day and you don’t even have to be there for it to happen.
Find out more about Tasks and the Tasks Scheduler in the Studio 3T Knowledge Base.