用于对mongodb上的时间序列进行版本化的文档结构 [英] structure of documents for versioning of a time series on mongodb
问题描述
我有一个时间系列,可以通过时间修改:
I have a time series that grows and is (potentially) revised through time:
2013-01-0110在2013-01-02上的
"2013-01-01" 10
2013-01-0111
"2013-01-01" 11
2013-01-0111
2013-02-01 20
"2013-01-01" 11
"2013-02-01" 20
2013-01-0111
2013-02-0121
"2013-01-01" 11
"2013-02-01" 21
2013-01-0111
2013-02-0121
"2013-01-01" 11
"2013-02-01" 21
例如,使用2013-02-01查询,我需要获得
2013-01-0111
2013-02-0120
For instance, querying with "2013-02-01", I need to get
"2013-01-01" 11
"2013-02-01" 20
我的文档,和我来自关系背景,我不知道我的结构的影响。
I need help to structure my documents, and as I come from a relational background, I am not sure about the implications of my structure. I have basically identified 2 possible structure, and would be happy to have some feedbacks, or suggestions of other structure.
{
"id":"1",
"date":"2013-01-01",
"version_date":"2013-01-01",
"value":10
}
{
"id":"1",
"date":"2013-01-01",
"version_date":"2013-01-02",
"value":11
}
{
"id":"1",
"date":"2013-02-01",
"version_date":"2013-02-01",
"value":20
}
{
"id":"1",
"date":"2013-02-01",
"version_date":"2013-02-02",
"value":21
}
选项B:一个文档包含一个日期的所有修订
OPTION B: One document contains all the revisions of one date
{
"id":"1",
"date":"2013-01-01",
"values" : [
{ "version_date":"2013-01-01",
"value":10
},
{
"version_date":"2013-01-02",
"value":11
}
}
{
"id":"1",
"date":"2013-02-01",
"values" : [
{ "version_date":"2013-02-01",
"value":20
},
{
"version_date":"2013-02-02",
"value":21
}
}
在选项B中,我还担心执行更新查询可能会有点困难,因为文档有不断增长的部分,我不确定是否支持/为mongodb
In option B, I am also concerned by the fact that it might be a bit more difficult to perform the update query as the document has a growing part, which i am not sure is very well supported by / optimised for mongodb
编辑:我也考虑选项C加快query1:(虽然它可能减慢一点写)
I am also considering option C to speed up query1: (although it might slow down a bit the writing)
{
"id":"1",
"date":"2013-01-01",
"values" : [
{ "version_date":"2013-01-01",
"value":10
},
{
"version_date":"2013-01-02",
"value":11
}
"last_value":11
}
{
"id":"1",
"date":"2013-02-01",
"values" : [
{ "version_date":"2013-02-01",
"value":20
},
{
"version_date":"2013-02-02",
"value":21
}
"last_value":21
}
推荐答案
最近的博客帖子在涵盖这个主题的官方网页: http://blog.mongodb.org/post/65517193370/schema-design-for-time-series-data-in-mongodb
查看一下,并询问任何其他问题如果需要。
There's actually a very recent blog post on the official page covering this topic: http://blog.mongodb.org/post/65517193370/schema-design-for-time-series-data-in-mongodb Take a look at that and ask any additional questions if required.
这篇关于用于对mongodb上的时间序列进行版本化的文档结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!