When people are building their MongoDB queries in Studio 3T, they may miss some Visual Query Builder features. Like it allows you to “turn off” whole parts of your query. You can then toggle in and out of the filtered and unfiltered results. It gives you a better view of your data so you can build better queries.
The Visual Query Builder in Studio 3T is a great way to build MongoDB queries. You can assemble your query with drag and drop then see its whole structure at a glance. The Visual Query Builder is full of powerful features. One of the most powerful features are the checkboxes on the right of the builder. These let you turn on and off queries and other elements of queries on demand.
These enable you to quickly move from filtered to partially filtered to unfiltered results, and back, without rewriting your query. Take this Visual Query Builder view:
There’s a lot of blue ticks on the right hand side of the Visual Query Builder. Each one can radically change how this query is run.
Ticking the Right Box
The rule of thumb is that the checkbox enables or disables whatever box it is in. So, let’s start with the checkbox that will have the most effect.
Top-right, in the Query panel. This toggles the entire Query in and out of use. Toggle it off and then click run and none of the query will be used – you’ll be matching everything. Great for flipping back to the completely unfiltered set of results. This, though, isn’t very granular. Let’s get precise!
Next to each element of the query there is a check box too. In this case a >=
comparison on transaction_count and a Studio 3T date tag (super time saver!) comparison with bucket_end_date. This is the granular control for each part of the query.
Uncheck the checkbox in the transaction_count comparison and click run. The query runs without that one comparison – the date comparison remains. Now we can use this to quickly see the effect of that one comparison on our results.
If you create an And/Or group, the group also has its own checkbox. You can use that to toggle the entire group in and out of the query.
If you are feeling creative, you can also set up multiple different conditions. Then you can toggle in and out the ones you are interested in for any particular scenario. But, before you go and save your super-query, do toggle all the checkboxes on. That’s because bookmarking a query saves the actual effective query, not the entire contents of the Visual Query Builder.
Project Yourself
Also super useful is the ability to toggle in and out the projection section. You can toggle your entire projection section off, click Run and see all the fields. You can see the effect in this composite screenshot below. In the upper part, the projection is filtering out a number of fields. Just unchecking the Projection toggle takes you from the upper to the lower view…
…and its here you can see, without modifying the projection settings, the hidden fields are now visible. Toggling the projection checkbox again will restore the projection’s effect on the results.
This is especially handy if you’ve forgotten what other fields are available to work with. You can also go granular and toggle in and out particular fields from your projection.
Sort it out
Finally, we get to the Sort element. As you would expect, you can turn the entire sort option on or off easily. This gives you a view of your unordered results. More usefully, you have the granular option of toggling the presence of each sort specification. This is particularly useful when you are trying to add a multi-field ordering to your results. Remember you also have the ability to simply move items up and down the sort order.
Toggle Power
Just by toggling the checkboxes in the Visual Query Builder, you can begin to really explore how your queries work. That means you can quickly test alternative strategies.