时间戳作为 mongodb 中的键作为时间序列数据库

Timestamp as Key in mongodb as timeseries database

我想使用 mongodb 作为时间序列数据库并通过时间戳 + id 进行查询。

Mongodb如图所示一种存储数据的方式here.

{
  timestamp_hour: ISODate("2013-10-10T23:00:00.000Z"),
  ID: “System1”,
  values: {
    0: { 0: 999999, 1: 999999, …, 59: 1000000 },
    1: { 0: 2000000, 1: 2000000, …, 59: 1000000 },
    …,
    58: { 0: 1600000, 1: 1200000, …, 59: 1100000 },
    59: { 0: 1300000, 1: 1400000, …, 59: 1500000 }
  }
}

但我有多个值,每个值都有一个时间戳,它不是周期性的。 数据有一段时间的延迟或几天不来。 所以我不想用 0-24 来表示我的小时数,也不想用 0-59 来表示我的分钟数。 我可以改用我测量的时间戳吗?我文档中的每个值都有相同的时间戳,所以如果 value1 有 50 个条目,value2 也有 50 个条目和相同的时间戳。

     {
          timestamp_hour: ISODate("2013-10-10T23:00:00.000Z"),
          ID: “System1”,
          values1: {
            "2013-10-10T22:00: {
         "2013-10-10T22:01:00.000Z": 999999, 
         "2013-10-10T22:02:00.000Z": 999999,
         "2013-10-10T22:03:00.000Z": 1000000 
                                },
            "2013-10-10T23:00:": { 
         "2013-10-10T23:01:00.000Z": 2000000,
         "2013-10-10T23:02:00.000Z": 2000000, 
                                 },
          }
         values2: {
            "2013-10-10T22:00: {
         "2013-10-10T22:01:00.000Z": 999999, 
         "2013-10-10T22:02:00.000Z": 999999,
         "2013-10-10T22:03:00.000Z": 1000000 
                                },
            "2013-10-10T23:00:": { 
         "2013-10-10T23:01:00.000Z": 2000000,
         "2013-10-10T23:02:00.000Z": 2000000, 
                                 },
         }
    }

您可以使用传入的时间戳存储您的值,并使用单独的 mongodb map-reduce process to transform your values and store them in different collections with the granularity you need (ex. hourly, daily, monthly). See also incremental map-reduce

您还可以找到这些鼓舞人心的帖子:

这是一个非常糟糕的选择。当然你可以这样存储数据。但是当数据量很大的时候,比如海量的数据采集点,每个点都有海量的数据(比如间隔10秒),MongoDB就会变成噩梦。

尝试对时间序列数据使用实时时间序列数据库。