Filter Chart Results¶
On this page
Filters display a subset of results that match a given criteria. MongoDB Charts provides two ways to filter the data for a single chart. You can either use:
- The Filter Tab's numeric, string, date, or boolean fields to handle most of your data filtering needs.
- The Query Bar to filter your data using more complex queries, such as logical operator queries, or process raw data by using the aggregation pipeline.
To learn how to filter results across multiple charts on your dashboard, see Filter Dashboards by Field Values.
Create Filters for Your Data¶
The chart builder contains a filter tab where you can drag and drop fields to specify filters for your data. To filter data using the filter tab:
Click the center tab in the chart builder:
- Drag a field from the Fields on the left to the Chart Filters section of the tab.
The data type of the selected field determines the available filtering options. You can filter fields with the following data types:
You cannot use the same field in multiple filters.
Enable or Disable a Filter¶
You can toggle whether a filter in the Filter tab is enabled or disabled. Disabled filters do not affect the documents which appear in the chart. Disabled filters are grayed out and cannot be edited until they are enabled.
To toggle whether a filter is enabled, hover over a filter and set the toggle that appears at the top of the filter to the desired setting.
Expand or Collapse a Filter¶
You can expand or collapse chart filter cards by clicking Show or Hide on that card.
Disabled filters are automatically collapsed.
Enabled, collapsed filters are still applied to your charts.
Filter Your Data Using the Query Bar¶
The Query bar above the chart display supports more complex queries than the filter panel. Additionally, you can use the query bar to create aggregation pipelines to process your data before it is rendered.
To filter data using the Query bar:
- In the Query bar, input a filter document. Use the same syntax used in the query portion of the db.collection.find() method. Your filter document must be in curly brackets.
- Click Apply.
Address Query Errors¶
If your query is invalid, Charts displays the icon in the Query bar.
Click the Query bar if it is not already displayed to view error details. Charts displays error details for:
- Client-side errors, such as malformed JSON, and
- Server-side errors, such as invalid MQL.
Review the error details, then adjust your query accordingly.
- Filters on large collections may encounter performance issues if the collection is not appropriately indexed.
The date functions used in the MongoDB Charts query bar are consistent and compatible with the date functions used in the mongo shell. As a result, you can use:
Date()function (as opposed to the
new Date()constructor) returns the current date as a string, so it cannot be used for querying dates in Charts.