In this exercise, you’ll create a simple query that limits the pubs in the british_pubs
collection to those located in Scotland. You’ll then export the query results to a .json file.
To export the documents
1. On the british_pubs
collection tab, select the Table View option.
2. Double-click any value in the address field.
The Result tab now displays the fields in the embedded document associated with each document’s top-level address field, as shown in the following figure.
3. Near the top right corner of the collection tab, click on Visual Query Builder to open it.
4. On the Result tab, locate one of the Scotland
values in the Region
column and drag the value to the first text box in the Query section of the query form. (The text box tip reads Drag field here or double-click.)
Your query form should look similar to the following figure.
5. In the Query section of the query form, click the Run button.
The Result tab should now show only Scottish pubs.
6. Click on Hide Query Builder to close it.
7. Click Export on the toolbar to launch the Export Wizard.
8. On the Export source page of the Export Wizard, select the Current Query Result option, and then click Next.
9. On the Select the export format page, select JSON and then click Finish.
10. This will open the Export unit #1 – JSON tab, seen below.
Here we’ll do a couple of things:
- Under Format options, choose JSON – mongo shell / Studio 3T
- Under Select target, choose File
You can also choose to include commas between documents or export the documents as an array, depending on how you’ll use the export file, under Other options.
11. Click the folder icon to the right of the File text box.
12. In the file manager text box, type scottish_pubs.json in the Save As text box.
13. Navigate to the target folder, and then click Save.
14. Browse through the Output Preview section to check that the export looks correct.
15. On the top toolbar, click on Execute to run the export.
16. Verify that the scottish_pubs.json export file has been created. Right-click on the export in the Operations window and choose Open in File Explorer (Windows and Linux) or Reveal in Finder (macOS).
You can use a text editor to confirm that the file contains the exported documents.