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.
创建图表视图后,您可以在创建图表时选择图表视图作为数据源。
用例
如果您的collection数据未针对数据可视化进行优化,则使用管道对数据源进行预处理非常有用。
预处理数据有助于完成以下任务:
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.
从collection创建Charts视图
连接您的部署。
要了解更多信息,请参阅将部署连接到 Charts。
示例管道
连接两个collection中的数据
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' } } ]
隐藏敏感数据
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.
转换数据字段的类型
以下示例将管道添加到包含我们要转换为日期的字符串字段的数据源。管道向数据源添加一个新字段,其中字符串字段saleDate转换为名为saleDateAsDate的日期字段:
[ { $addFields: { saleDateAsDate: { $toDate: '$saleDate' } } } ]
修改Charts视图的管道
断开Charts视图连接
要断开Atlas Charts视图的连接,请参阅断开数据源的连接。
删除Charts视图
If you are the Project Owner, you can permanently delete a charts view.
要删除Atlas Charts视图,请执行以下操作:
连接您的部署。
要了解更多信息,请参阅将部署连接到 Charts。