Mongo for non regular time-series

六月ゝ 毕业季﹏ 提交于 2019-12-07 09:15:46

You may still be able to reap the benefit of having a preallocated document even if readings aren't uniformly distributed. You can't structure each document by the time of the readings, but you can structure each document to hold a fixed number of readings

{
    "type" : "cookies consumed"
    "0" : { "number" : 1, "timestamp" : ISODate("2015-02-09T19:00:20.309Z") },
    "1" : { "number" : 4, "timestamp" : ISODate("2015-02-09T19:03:25.874Z") },
    ...
    "1000" : { "number" : 0, "timestamp" : ISODate("2015-01-01T00:00:00Z") }
}

Depending on your use case, this structure might work for you and give you the benefit of updating preallocated documents with new readings, only allocating a brand new document every N readings for some big N.

The solution to your problem is very well captured here:

http://bluxte.net/musings/2015/01/21/efficient-storage-non-periodic-time-series-mongodb

Basic idea as already pointed out is: to have fixed number of events captured per document and keep a track record of the start and end time stamp of each document in another "higher-level" collection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!