From 76cf5cbb4f1759e126ab8dbc5318f4906c8d6a65 Mon Sep 17 00:00:00 2001 From: Maz Ameli <maz@metabase.com> Date: Thu, 19 Dec 2019 11:38:03 -0800 Subject: [PATCH] Fix mongo optional clause example (#11552) * fix mongo optional clause example [ci skip] * run tests --- docs/users-guide/13-sql-parameters.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/users-guide/13-sql-parameters.md b/docs/users-guide/13-sql-parameters.md index 5f1f1f91d21..412b7cdb1e6 100644 --- a/docs/users-guide/13-sql-parameters.md +++ b/docs/users-guide/13-sql-parameters.md @@ -23,7 +23,7 @@ WHERE category = {% raw %}{{cat}}{% endraw %} If you're writing a native MongoDB query, your query would look more like this, with the `cat` variable being defined inside of the `match` clause. ``` -{% raw %}[{ $match: { _category: {{cat}} } }]{% endraw %} +{% raw %}[{ $match: { category: {{cat}} } }]{% endraw %} ``` ### The Field Filter variable type @@ -33,7 +33,7 @@ Setting a variable to the "Field Filter" type allows you to map it to a field in A field filter variable inserts SQL similar to that generated by the GUI query builder when adding filters on existing columns. This is useful because it lets you do things like insert dynamic date range filters into your native query. When adding a field filter, you should link that variable to a specific column. Field filter variables should be used inside of a `WHERE` clause in SQL, or a `$match` clause in MongoDB. **Note:** Table aliases are not supported. This is because field filters generate SQL based on the mapped field. -Some databases require the schema in the `FROM` clause. An example for Oracle would be `FROM "schema"."table"`. In BigQuery, back ticks are needed, like ``FROM `dataset_name.table` ``. +Some databases require the schema in the `FROM` clause. An example for Oracle would be `FROM "schema"."table"`. In BigQuery, back ticks are needed, like `` FROM `dataset_name.table` ``. Example: @@ -63,7 +63,7 @@ First, insert a variable tag in your SQL, like `{% raw %}{{my_var}}{% endraw %}` - UNIX Timestamp (Milliseconds) - ZIP or Postal Code -The field can also be a datetime one (which can be left as "No special type" in the Data Model). +The field can also be a datetime, which can be left as "No special type" in the Data Model. You'll then see a dropdown labeled "Widget," which will let you choose the kind of filter widget you want on your question, which is especially useful for datetime fields. You can select "None" if you don't want a widget on the question at all, which you might do e.g. if you're just wanting to allow this question to be mapped to a dashboard filter (see more on that below). @@ -119,7 +119,16 @@ FROM products Or in MongoDB: ``` -{% raw %}[{ $match: { [[ _category: {{cat}} ]] } }]{% endraw %} +{% raw %} +[ + [[{ + $match: {category: {{cat}}} + },]] + { + $count: "Total" + } +] +{% endraw %} ``` To use multiple optional clauses you must include at least one regular `WHERE` clause followed by optional clauses, each starting with `AND`. -- GitLab