在mongodb中存储温度数据的最佳方法
我有一个关于温度数据的问题: 使用mysql,我存储的温度数据如下:在mongodb中存储温度数据的最佳方法,mongodb,Mongodb,我有一个关于温度数据的问题: 使用mysql,我存储的温度数据如下: city_id;city_name;month;min_temperature,max_temperature 123,New York,1,7,9 { "_id" : 20480, "name": "New York" "climate" : { "air" : { "1" : { "min" : "1", "max" : "8" },
city_id;city_name;month;min_temperature,max_temperature
123,New York,1,7,9
{
"_id" : 20480,
"name": "New York"
"climate" : {
"air" : {
"1" : {
"min" : "1",
"max" : "8"
},
"2" : {
"min" : "2",
"max" : "8"
},
"3" : {
"min" : "3",
"max" : "10"
},
"..."
}
}
}
{
"_id" : 20480,
"name": "New York"
"climate" : {
"air" : {
"january" : {
"min" : "1",
"max" : "8"
},
"february" : {
"min" : "2",
"max" : "8"
},
"march" : {
"min" : "3",
"max" : "10"
},
"..."
}
}
}
现在我想转到mongodb,并希望存储面向对象的数据文档
现在的结构如下所示:
city_id;city_name;month;min_temperature,max_temperature
123,New York,1,7,9
{
"_id" : 20480,
"name": "New York"
"climate" : {
"air" : {
"1" : {
"min" : "1",
"max" : "8"
},
"2" : {
"min" : "2",
"max" : "8"
},
"3" : {
"min" : "3",
"max" : "10"
},
"..."
}
}
}
{
"_id" : 20480,
"name": "New York"
"climate" : {
"air" : {
"january" : {
"min" : "1",
"max" : "8"
},
"february" : {
"min" : "2",
"max" : "8"
},
"march" : {
"min" : "3",
"max" : "10"
},
"..."
}
}
}
有没有人对这种结构有过一些经验,或者有什么建议可以优化这种结构?
这种结构有意义吗?还是这样做更好:
city_id;city_name;month;min_temperature,max_temperature
123,New York,1,7,9
{
"_id" : 20480,
"name": "New York"
"climate" : {
"air" : {
"1" : {
"min" : "1",
"max" : "8"
},
"2" : {
"min" : "2",
"max" : "8"
},
"3" : {
"min" : "3",
"max" : "10"
},
"..."
}
}
}
{
"_id" : 20480,
"name": "New York"
"climate" : {
"air" : {
"january" : {
"min" : "1",
"max" : "8"
},
"february" : {
"min" : "2",
"max" : "8"
},
"march" : {
"min" : "3",
"max" : "10"
},
"..."
}
}
}
任何帮助都会很好。任何一个都会很好。
或者,您也可以选择:
"air" : [{min:1,max:5},{min:2,max:6}, {min:5,max:15} ... ]
改用数组。当然,0=1月
这取决于您是在climate.air.january中执行更多操作,还是在climate.air[0]中执行循环并执行更多操作
- 现在,您需要考虑对数据进行何种查询。例如
a) 哪个城市在三月份的气温最高?
b) 哪些城市的最高气温在8到12之间 c) 哪个城市全年平均最低气温最高?等
希望这有帮助。谢谢你的回答。但是,使用您提到的阵列结构是否有一些优势?