Skip to content

Commit 6650172

Browse files
(DOCSP-6314): Adding filter query param docs for embedding (#220)
* (DOCSP-6314): Adding filter query param docs for embedding * Updates per Tom's feedback * test error fix * re-adding content * Fixing broken links * minor tweaks * Reformatting * Updates per Tom's feedback * adding line at eof
1 parent ef39d9a commit 6650172

File tree

1 file changed

+122
-2
lines changed

1 file changed

+122
-2
lines changed

source/embedded-chart-options.txt

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,59 @@ query parameters to their iframe URLs.
1919
options on your data sources. For instructions, see
2020
:ref:`embedding-charts`.
2121

22-
Specify Refresh Interval
23-
------------------------
22+
Query Parameter Order for Verified Signatures
23+
---------------------------------------------
24+
25+
If you are using a :ref:`Verified Signature <embedding-procedure>` to
26+
render your chart, you must specify the query parameters of your
27+
payload in the following order, or else your signature verification
28+
will fail:
29+
30+
.. list-table::
31+
:header-rows: 1
32+
:widths: 10 20 40
33+
34+
* - Parameter Position
35+
- Name
36+
- Description
37+
38+
* - 1
39+
- ``id``
40+
- ``id`` parameter from the Embed Chart snippet.
41+
42+
* - 2
43+
- ``tenant``
44+
- ``tenant`` parameter from the Embed Chart snippet.
45+
46+
* - 3
47+
- ``timestamp``
48+
- Current time.
49+
50+
* - 4
51+
- ``expires-in``
52+
- *(Optional)* Number of seconds for which the signature is valid.
53+
If omitted, the signature is valid for 24 hours after it is
54+
created.
55+
56+
* - 5
57+
- ``filter``
58+
- *(Optional)* MQL document to filter rendered documents.
59+
See :ref:`embed-options-filter`.
60+
61+
* - 6
62+
- ``autorefresh``
63+
- *(Optional)* Interval in seconds at which the chart refreshes.
64+
See :ref:`embed-options-refresh`.
65+
66+
The code examples on the
67+
`MongoDB Charts Embedding Examples <https://github.com/mongodb/charts-embedding-examples>`__
68+
GitHub page provide sample payload generations with properly-formatted
69+
query parameters.
70+
71+
.. _embed-options-refresh:
72+
73+
Specify a Refresh Interval
74+
--------------------------
2475

2576
Use the ``autorefresh`` query parameter to define the interval,
2677
in seconds, at which the chart refreshes with the latest data from
@@ -68,3 +119,72 @@ Considerations
68119
will not render and an error will be displayed as the signature is
69120
no longer valid. The host web page must regenerate a new signature
70121
to resume rendering the chart.
122+
123+
.. _embed-options-filter:
124+
125+
Specify a Filter
126+
----------------
127+
128+
Use the ``filter`` query parameter to only display data in your
129+
embedded chart which matches a specified :abbr:`MQL (MongoDB Query Language)`
130+
filter.
131+
132+
.. important::
133+
134+
For security reasons, the ``filter`` query parameter can only be used
135+
on charts embedded with a
136+
:ref:`Verified Signature <embedding-procedure>`. You should generate
137+
your ``filter`` in your server-side code, rather than receiving
138+
it from the client. Generating the filter from the server
139+
prevents the client from modifying the filter and potentially
140+
accessing restricted data.
141+
142+
Syntax
143+
~~~~~~
144+
145+
Specify an MQL document as your ``filter`` query parameter. Use the
146+
same syntax used in the :ref:`query bar <query-bar>` in the Chart
147+
Builder.
148+
149+
MQL queries contain characters that must be URL-encoded before
150+
your server-side code calculates the verified signature.
151+
When |charts-short| verifies the signature, it URL-encodes the filter
152+
again using the JavaScript
153+
`encodeURIComponent
154+
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent>`__
155+
function. This function encodes
156+
spaces as ``%20``, rather than ``+`` or a raw space. You must use the
157+
same ``encodeURIComponent`` encoding algorithm to encode your query. To
158+
see how correctly encode an MQL filter using different server-side
159+
programming languages, see `MongoDB Charts Embedding Examples
160+
<https://github.com/mongodb/charts-embedding-examples>`__ on GitHub.
161+
162+
Example
163+
~~~~~~~
164+
165+
The following iframe ``src`` URL renders a chart which only displays
166+
documents with an ``imdb.rating`` greater than or equal to ``8``:
167+
168+
.. code-block:: none
169+
:emphasize-lines: 6
170+
171+
https://charts.mongodb.com/charts-atlasproject1-piocy/embed/charts?
172+
id=93584ddb-1115-4a12-afd9-5129e47bbb0d&
173+
tenant=3397ee6d-5079-4a20-b097-cedd475220b5&
174+
timestamp=1564156636&
175+
expires-in=300&
176+
filter=%7B%22imdb.rating%22%3A%20%7B%24gte%3A%208%7D%7D&
177+
autorefresh=30&
178+
signature=8e0d92b33934c928f6c6974e2f0102ace77f56d851cb0d33893e84c359ab1043
179+
180+
The URL uses an encoded ``filter`` parameter of
181+
``%7B%22imdb.rating%22%3A%20%7B%24gte%3A%208%7D%7D``. Decoded, this
182+
filter is:
183+
184+
.. code-block:: json
185+
186+
{"imdb.rating": {$gte: 8}}
187+
188+
The server-side code creates a payload with the necessary information
189+
to render the chart, including the filter. The payload ensures that
190+
the verified signature is valid before rendering the chart.

0 commit comments

Comments
 (0)