名词解释
Glossary
bucket:带有相同的元数据且在一段有限制的间 隔区间内的测量值组。
bucket collection :用于存储时序型集合的底层的分组桶的系统集合。复制、分片和索引都是在桶级别上完成的。
measurement:带有特定时间序列的K-V集合。
meta-data:时序序列里很少随时间变化的K-V对,同时可以用于识别整个时序序列。
time-series:一段间隔内的一系列测量值。
time-series collection:一种表示可写的非物化的视图的集合类型,它允许存储和查询多个时间序列,每个序列可以有不同的元数据。
MongoDB 在5.0中支持了新的timeseries collection
类型的选项,该类型用于存储时序型数据。timeseries collection
提供了一组用于插入和查询测量值的简单接口,同时底层实际的数据是存储在以bucket
形式的集合中。
在创建timeseries collection
时,timeField
字段是最小必备的配置项。metaField
是另一个可选的、可被指定的元数据字段,它是用于在bucket
中对测量值分组的依据。MongoDB通过提供expireAfterSeconds
字段选项,也支持了对测量值的过期机制。
在mydb
数据库中有个以mytscoll
命名的timeseries collection
,该集合在MongoDB内部的catelog
(用于存储集合或视图的信息)里是由一个视图和一个系统集合组成的。
-
mydb.mytscoll
是个视图,它在MongoDB底层是用bucket collection
作为包含特定属性的原始集合实现的:-
该视图就是通过
aggregation
里的$_internalUnpackBucket
来实现展开bucket
里数据的。 -
该视图是可写的(仅支持插入)。同时每个被插入的文档必须包含时间字段。
-
在查询视图时,它会隐式地展开底层在
bucket collection
中存储的数据,然后返回原始的非bucket
形式的文档数据。
-
-
该系统集合的命名空间是
mydb.system.buckets.mytscoll
,它是用来存储实际数据的。-
每一个在
bucket collection
里的文档,都表示了一组区间间隔的时序型数据。 -
如果在创建
timeseries collection
时,定义了metaField
元数据字段,那么所有在bucket
里的测量值都会有这个通用的元数据字段。 -
除了时间范围,
bucket
还限制了每个文档数据的总条数以及测量值的大小。
-
Bucket Collection Schema
{
_id: <Object ID with time component equal to control.min.<time field>>,
control: {
// <Some statistics on the measurements such min/max values of data fields>
version: 1, // Version of bucket schema. Currently fixed at 1 since this is the
// first iteration of time-series collections.
min: {
<time field>: <time of first measurement in this bucket, rounded down based on granularity>,
<field0>: <minimum value of 'field0' across a