Build Materialized Views on Top of Time Series Data在时间序列数据之上构建物化视图
Materialized views on time series data are useful for:时间序列数据的物化视图可用于:
- archiving
- analytics
facilitating data access for teams that cannot access the raw data为无法访问原始数据的团队提供数据访问便利
To create an On-Demand Materialized view, use the 要创建按需物化视图,请使用$merge aggregation pipeline stage to transform and store your data:$merge聚合管道阶段转换和存储数据:
db.weather.aggregate([
{
$project: {
date: {
$dateToParts: { date: "$timestamp" }
},
temp: 1
}
},
{
$group: {
_id: {
date: {
year: "$date.year",
month: "$date.month",
day: "$date.day"
}
},
avgTmp: { $avg: "$temp" }
}
}, {
$merge: { into: "dailytemperatureaverages", whenMatched: "replace" }
}
])
The preceding pipeline, will create or update the 前面的管道将根据dailytemperatureaverages collection with all daily temperature averages based on the weather collection.weather集合创建或更新dailytemperatureaverages集合。
Note
It is not possible to natively schedule the refreshing of these materialized views.不可能以本机方式安排这些具体化视图的刷新。
For more information on materialized views, see On-Demand Materialized Views.有关物化视图的更多信息,请参阅按需物化视图。