开始学习MongoDB + node.js. 为了练习,我想创建收集数据和绘制信息图的webapp。但是我为MongoDB库选择数据模型有很大的问题。
现在如何运作,但我认为结构不好。
我的服务每小时从API检索所有数据并将其收集在集合" accounts"中。
主要问题:这样做可以:每个小时的特殊对象" expStart"使用由请求时间生成的唯一键?
来自集合"帐户"的一个文档的结构:
{
"_id" : ObjectId("54bd56cb699f4890160aacc9"),
"name" : "Shubiii",
"characters" : [
{
"online" : false,
"rank" : 562,
"dead" : false,
"name" : "ShrupShurp",
"league" : "hardcore",
"level" : 93,
"class" : "Ranger",
"experience" : 2515197599,
"expStat" : {
"dd2015_1_19_19_9" : 122120,
"dd2015_1_19_20_11" :45222
}
},
{
"online" : false,
"rank" : 563,
"dead" : false,
"name" : "ShrupShurp2",
"league" : "hardcore",
"level" : 93,
"class" : "Ranger",
"experience" : 2515197599,
"expStat" : {
"dd2015_1_19_19_9" : 3122120,
"dd2015_1_19_20_11" :21212
}
}
],
"challenges" : {
"total" : 3
},
"twitch" : {
"name" : ""
}
}
这是API数据结构(http://www.pathofexile.com/developer/docs/api):
{
"total": 15000,
"entries": [
{
"online": false,
"rank": 2,
"dead": false,
"character": {
"name": "iamgodyi",
"level": 100,
"class": "Ranger",
"experience": 4250334444
},
"account": {
"name": "TW_James",
"challenges": {
"total": 0
},
"twitch": {
"name": "destiny601"
}
}
},
{
"online": true,
"rank": 3,
"dead": false,
"character": {
"name": "xVisco",
"level": 100,
"class": "Templar",
"experience": 4250334444
},
"account": {
"name": "xVisco",
"challenges": {
"total": 0
}
}
}
]
}
抱歉我的英文。
答案 0 :(得分:0)
您可以使用此结构。
{
"_id" : ObjectId("54bd56cb699f4890160aacc9"),
"name" : "Shubiii",
"characters" : {
"online" : false,
"rank" : 562,
"dead" : false,
"name" : "ShrupShurp",
"league" : "hardcore",
"level" : 93,
"class" : "Ranger",
"experience" : 2515197599,
"expStat" : {
"dd2015_1_19_19_9" : 122120,
"dd2015_1_19_20_11" :45222
}
},
"challenges" : {
"total" : 3
},
"twitch" : {
"name" : ""
}
}