In this exercise, you’ll use Visual Query Builder to build and run a query that retrieves documents from the
customers collection. The query will be based on a single value (
Database) in the
To build the query in Visual Query Builder
1. Find the
customers collection in the Connection Tree and double-click to open it. It will open its own tab.
2. Over on the upper right-hand side, click Visual Query Builder to launch it.
3. In the Query section of the query form, select the Has array element(s) matching option from the drop-down list in the upper left corner.
Studio 3T adds the Array drop-down list to the top of the Query section, as shown in the following figure.
4. From the Array drop-down list, select the interests field, which is configured with the
Array data type.
5. Click the Add button in the box at the bottom of the Query section. The form will expand to include options for defining a search condition, as shown in the following figure.
6. In the first drop-down list in the new search condition section, ensure that <Array Element> is selected, and in the second drop-down list (the one to the right of the first list), ensure that equals is selected.
These options are typically selected by default, as indicated in the previous figure, but you should verify them anyway.
7. In the text box beneath the two drop-down lists, type Database.
8. In the main window on the customers collection’s Result tab, select the Tree View option if it’s not already chosen. Then, expand the first record if needed.
9. Drag the last field to the box at the bottom of the Projection section of the query form.
10. Drag the interests field to the same box in the Projection section. Your query form should now look like the following figure.
11. On the query form, click the Run button in the upper right corner.
You’ll now see the results in the
customers collection’s Result tab, and that the query has returned 22 documents.
12. Switch back to Table View.
If the values in the
interests array are not displayed, right-click a value in the interests column and then click Show Embedded Fields. The query should have returned 22 documents, as shown in the following figure.
13. Go to the Query Code tab and view the mongo shell code. It should look similar to the first
find statement you created in the previous exercise, as shown in the following figure.
14. Leave the customers collection tab and Visual Query Builder form in place for the next exercise.