Create and Manage Charts Views
On this page
If you are the Project Owner
, you can create and modify
a charts view. A charts view is a data source that applies an
aggregation pipeline
to a collection to pre-process data before it is used for
Charts. You can create multiple charts views from a single
collection.
After you create a charts view, you can select the charts view as a data source when you create a chart.
Use Cases
Pre-processing a data source with a pipeline is useful when your collection data is not optimized for data visualization.
Pre-processing your data can help accomplish the following tasks:
Join data from multiple collections into a single data source using
$lookup
. See example.Hide fields which may contain sensitive data from Charts users using
$project
. See example.Convert data types, such as a string field to a date. See example.
Create a Charts View from a Collection
Connect your deployment.
To learn more, see Connect a Deployment to Charts.
Select a database and collection.
In the deployment's Data Access section, click the name of the database that contains the collection to use for the charts view. The collections list appears.
Click the collection to use for the charts view. Charts also displays any existing charts views that use the collection.
(Optional) Click Test Pipeline.
Atlas Charts validates your pipeline. Charts reports any errors in your pipeline below the editor. If the pipeline is valid, Charts shows a sample document from the results or displays No documents returned.
Tip
For help creating your pipeline, you can utilize the Aggregation Pipeline Builder in the Atlas Data Explorer.
You can create your pipeline using the Atlas pipeline builder and paste it into the Atlas Charts pipeline editor.
Example Pipelines
Join Data from Two Collections
The following example adds a pipeline to a data source pointing to
the sample_mflix.movies
collection from the
Sample Mflix Dataset provided by
Atlas. The pipeline performs a $lookup
to join data
from the comments
collection based on movie_id
. The result is
a new field in this data source called comments
containing data
from a separate collection.
[ { $lookup: { from: 'comments', localField: '_id', foreignField: 'movie_id', as: 'comments' } } ]
Hide Sensitive Data
The following example adds a pipeline to a data source pointing to the
sample_supplies.sales
collection from the
Sample Supply Store Dataset
provided by Atlas. The pipeline hides the customer.email
field,
making that field unavailable to charts using this data source:
[ { $project: { "customer.email": 0 } } ]
To learn more about the $project
aggregation stage,
see $project
.
Convert the Type of a Data Field
The following example adds a pipeline to a data source containing a
string field that we want to convert to a date. The pipeline adds a new
field to the data source with the string field saleDate
converted to
a date field called saleDateAsDate
:
[ { $addFields: { saleDateAsDate: { $toDate: '$saleDate' } } } ]
Modify a Charts View's Pipeline
Connect your deployment.
To learn more, see Connect a Deployment to Charts.
Select the database and collection.
In the deployment's Data Access section, click the name of the database that contains the collection associated with the charts view.
Click the name of the collection associated with the charts view. Charts displays information for all existing charts view that use the collection.
Disconnect a Charts View
To disconnect a charts view, see disconnect a data source.
Delete a Charts View
If you are the Project Owner
, you can permanently delete a
charts view.
To delete a charts view:
Connect your deployment.
To learn more, see Connect a Deployment to Charts.
Select the database and collection.
In the deployment's Data Access section, click the name of the database that contains the collection associated with the charts view.
Click the name of the collection associated with the charts view. Charts displays information for all existing charts views based upon the collection.