What's new

How do you make Studio 3T export MongoDB collections to unique files? #Studio3T_AMA

How do you make Studio 3T export MongoDB data with unique filenames ? Find out how to avoid accidental overwriting in Ask Manatees Anything #Studio3T_AMA

Studio 3T logo

Q: Help! I’ve been using Studio 3T to regularly export MongoDB collections to track our international shipments, but when I went to check the data, I found it has been overwriting previous exports. While I’m rebuilding my historical data, I want to know is there any way to force scheduled exports to write to a uniquely named file each 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: It is true that, historically, when an Export Task was run on Studio 3T, each Export Unit wrote its results to the file. That file is at the filename and path which is shown in the Export Unit’s destination field. If that file/filename wasn’t changed between runs of the Task, the files that were previously generated there are overwritten with the new results. The filename was unchanging by default.

Enter Placeholders For Export

Or at least that has been the case until Studio 3T 2021.6 and the introduction of placeholders. Placeholders are small text snippets that are automatically replaced with dynamic text when the export unit is used to write a file. There are three placeholders currently:

Where a filename field can make use of placeholders, you’ll find a ${} icon next to it. Clicking on the drop box next to it will reveal all the placeholders available:

The export destination field has a placeholder menu.

The Placeholder Menu

Selecting one of the placeholders in the menu here will insert the text into the file name at the current cursor position. You can type the placeholder string yourself if you wish. If you want to go back to the original generated filename, with no placeholders, just select Reset to default.

You can use a placeholder anywhere in the filename, including in the directory path. So say you have something like:

        /home/dj/myexports/exports${date}/report1-${time}.json

This will create a date-stamped directory with the time-stamped exported file in it. Similarly you can make a date-time-stamped directory to hold all the named exported files in it.

Going Global

You won’t just find placeholders in the Export destinations fields. If you look in the Export Options, you’ll find you can use them as defaults in a task. This makes it easy to apply dynamic settings across entire Export Tasks.

Global Options for Export tasks include the ability to set folder and generated filename settings

Placeholders in Export Global Options

In Studio 3T 2021.5, this setting for target was just one field, now it’s two, one for the directory and one for the filename, and both support placeholders. There’s also one extra placeholder for the filename field here. The ${exportsource} placeholder is the name of the database and/or collection or query which is acting as the source of the data. You can mix that in with the data and time fields, or, as in the example above, just create a new dated directory for the export.

With placeholders you have the freedom to lay out your exports in a whole new organized structure on your disk. Or you can simply date-time-stamp your export files when you Export MongoDB data and never accidentally overwrite files again.

Blog archive

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes, including personalized advertising (“performance”), to provide you with additional functions (“functional”), and to show content from social media platforms, such as embedded videos (“social media”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in section 9 of our Privacy Policy.

Manage consent preferences