Skip to content
Snippets Groups Projects
Unverified Commit 76cf5cbb authored by Maz Ameli's avatar Maz Ameli Committed by GitHub
Browse files

Fix mongo optional clause example (#11552)

* fix mongo optional clause example [ci skip]

* run tests
parent bd838ca4
No related branches found
No related tags found
No related merge requests found
......@@ -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`.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment