Skip to content

Commit d3110bc

Browse files
Date Filter Updates (#169)
* Adding info for date filters * Apply suggestions from code review Co-Authored-By: jeff-allen-mongo <[email protected]> * Updates per Mellissa's feedback * Updates per Tom's feedback * Fixing date example
1 parent 54d990b commit d3110bc

File tree

4 files changed

+135
-61
lines changed

4 files changed

+135
-61
lines changed

source/filter-documents.txt

Lines changed: 134 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ options. You can filter fields with the following data types:
4646

4747
- :ref:`String <filter-string>`
4848

49+
- :ref:`Date <filter-date>`
50+
4951
.. note::
5052

5153
You cannot use the same field for multiple filters.
@@ -102,9 +104,6 @@ The list also includes:
102104
- :guilabel:`Empty String` for documents with ``""`` values for the
103105
field.
104106

105-
To include a value not displayed in the list, add a specific value by
106-
clicking :guilabel:`Add Value`.
107-
108107
Select the string values to display in the chart. By default, all
109108
values are selected.
110109

@@ -119,15 +118,126 @@ values are selected.
119118
Display Strings Not in the List
120119
```````````````````````````````
121120

122-
You can check :guilabel:`All other values` to
123-
display all string values not included in the list.
121+
To display a specific value not included in the list, add the value by
122+
clicking :guilabel:`Add Value`.
123+
124+
To display *all* other values not included in the list, check
125+
:guilabel:`All other values`.
124126

125127
- If :guilabel:`All other values` is checked, |charts| filters out
126128
any unchecked list items by using a :query:`$nin` query.
127129

128130
- If :guilabel:`All other values` is unchecked, |charts| only
129131
includes the checked list items by using an :query:`$in` query.
130132

133+
.. _filter-date:
134+
135+
Filter Date Fields
136+
~~~~~~~~~~~~~~~~~~
137+
138+
When you drag a date field to the filter panel, you can filter based
139+
on a specified date range. This range can either be:
140+
141+
- A :ref:`relative date <relative-date>` range, which specifies a range
142+
relative to the time the chart is rendered (e.g., the last six
143+
months).
144+
145+
- An :ref:`absolute date <absolute-date>` range, which is a range
146+
between specific beginning and end dates.
147+
148+
.. _relative-date:
149+
150+
Relative Date Filter
151+
````````````````````
152+
153+
Relative date filters specify a range relative to the
154+
time the chart is rendered. To define the date range, specify a period
155+
of time in the past and/or a period of time in the future relative to
156+
the current date. :guilabel:`Relative` is the default date filtering
157+
option.
158+
159+
To set a lower bound for a relative date filter:
160+
161+
1. Turn on the :guilabel:`From` toggle.
162+
163+
#. Set the lower bound for your relative date. This timespan is
164+
relative to the current date.
165+
166+
To set an upper bound for a relative date filter:
167+
168+
1. Turn on the :guilabel:`Until` toggle.
169+
170+
#. Set the upper bound for your relative date. This timespan is
171+
relative to the current date.
172+
173+
.. example::
174+
175+
The following relative date filter only shows documents
176+
with a ``Workout Date (As Date)`` field that is more recent than one year
177+
ago from the current date:
178+
179+
.. figure:: /images/charts/relative-date.png
180+
:scale: 60%
181+
:alt: Image showing relative date filter
182+
183+
.. _absolute-date:
184+
185+
Absolute Date Filter
186+
````````````````````
187+
188+
Absolute date filters use absolute dates to define their upper and lower
189+
bounds. To define an absolute date range, select :guilabel:`Absolute`
190+
at the top of your date filter card. The dates specified in the filter
191+
are assumed to be in :abbr:`UTC (Coordinated Universal Time)`, matching
192+
the raw data in the collection.
193+
194+
To define a lower bound for your absolute date filter:
195+
196+
1. Turn on the :guilabel:`From` toggle.
197+
198+
#. Enter a date for your lower bound, or
199+
select a date from the calendar below the input field.
200+
201+
#. Enter a time for your lower bound, or select a time
202+
from the list below the input field.
203+
204+
#. Set :guilabel:`Inclusive` to dictate whether to include
205+
the specified date.
206+
207+
To define an upper bound for your absolute date filter:
208+
209+
1. Turn on the :guilabel:`To` toggle.
210+
211+
#. Enter a date for your upper bound, or
212+
select a date from the calendar below the input field.
213+
214+
#. Enter a time for your upper bound, or select a time
215+
from the list below the input field.
216+
217+
#. Set :guilabel:`Inclusive` to dictate whether to include
218+
the specified date.
219+
220+
.. example::
221+
222+
The following absolute date filter only shows documents
223+
with a ``Workout Date (As Date)`` field from the year
224+
``2018``:
225+
226+
.. figure:: /images/charts/absolute-date.png
227+
:scale: 60%
228+
:alt: Image showing absolute date filter
229+
230+
|
231+
232+
The filter returns all documents with a
233+
``Workout Date (As Date)`` field from ``January 1, 2018 12:00:00
234+
AM`` inclusively, to ``January 1, 2019 12:00:00 AM`` exclusively.
235+
236+
.. note::
237+
238+
The date and time formats used in your bounds depend
239+
on your location, as determined from your browser settings.
240+
131241
.. _query-bar:
132242

133243
Query Bar
@@ -140,12 +250,27 @@ To filter data using the :guilabel:`Query` bar:
140250
:manual:`db.collection.find()
141251
</reference/method/db.collection.find/>` method.
142252

143-
#. Click :guilabel:`Apply`.
253+
#. Click :guilabel:`Apply`.
144254

145-
.. note::
255+
Considerations
256+
~~~~~~~~~~~~~~
257+
258+
- Filters on large collections may have performance issues if there
259+
are not appropriate :manual:`indexes <indexes>` on the collection.
260+
261+
- The date functions utilized in the |charts| query bar are consistent
262+
and compatible with the date functions used in the
263+
:manual:`mongo shell </mongo>`. As a result, you can use:
146264

147-
Filters on large collections may have performance issues if there
148-
are not appropriate :manual:`indexes <indexes>` on the collection.
265+
- ``new Date()``,
266+
- ``ISODate()``, or
267+
- ``new ISODate()``.
268+
269+
|
270+
271+
The ``Date()`` function (as opposed to the ``new Date()``
272+
constructor) returns the current date as a string, so it cannot be
273+
used for querying dates in |charts-short|.
149274

150275
Examples
151276
~~~~~~~~
@@ -196,54 +321,3 @@ letter ``A`` or ``a``, you would write the following in the
196321
.. code-block:: javascript
197322

198323
{ "job" : { $regex : "^A", $options : "i" } }
199-
200-
Date Range Query
201-
````````````````
202-
203-
The following query returns documents that have a
204-
``timestamp`` field between January 1, 2017 and December 31, 2017
205-
inclusively:
206-
207-
.. code-block:: javascript
208-
209-
{timestamp: {$gte: new Date("2017-01-01"), $lte: new Date("2017-12-31")}}
210-
211-
.. admonition:: ISO-8601 Dates
212-
:class: note
213-
214-
The date functions utilized in |charts| queries are consistent and
215-
compatible with the date functions used in the
216-
:manual:`mongo shell </mongo>`. As a result, you can use:
217-
218-
- ``new Date()``,
219-
- ``ISODate()``, or
220-
- ``new ISODate()``.
221-
222-
The ``Date()`` function (as opposed to the ``new Date()``
223-
constructor) returns the current date as a string, so it cannot be
224-
used for querying dates in |charts-short|.
225-
226-
.. _date-filter:
227-
228-
Relative Date Query
229-
```````````````````
230-
231-
You can include a mathematical expression in the ``new Date()``
232-
constructor to get a relative date, such as 1 month ago or 1 year
233-
ago.
234-
235-
For example, the following query returns documents that
236-
have a ``timestamp`` field greater than 30 days
237-
(30 * 24 * 60 * 60 * 1000 milliseconds) from the current date and time:
238-
239-
.. code-block:: javascript
240-
241-
{ timestamp: { $gt: new Date(new Date() - 30 * 24 * 60 * 60 * 1000 ) } }
242-
243-
Alternatively, you can specify the date components. For example, the
244-
following query returns documents that have a ``timestamp`` field
245-
greater than 1 month ago:
246-
247-
.. code-block:: javascript
248-
249-
{ timestamp: { $gt: new Date(new Date().getFullYear(), new Date().getMonth() -1 , new Date().getDate() ) } }
58.7 KB
Loading
43.1 KB
Loading

source/release-notes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Improvements in this release:
5555

5656
Bug fixes in this release:
5757

58-
- Changes to :ref:`filter parsing <date-filter>` to better align with
58+
- Changes to :ref:`filter parsing <filter-date>` to better align with
5959
MongoDB Shell syntax and Javascript in general. Specifically, filters
6060
using ``Date()`` to represent the current date or
6161
``Date("2019-01-01")`` to represent a specific date will need to be

0 commit comments

Comments
 (0)