我想将json对象分解为带有关系的sql表。我正在寻求帮助或任何好的建议,一个例子是完美的。我正在尝试编写一个脚本,将完整的json对象提取并加载到sql表中。首先,我必须先创建一个完美的sql表设置才能启动此过程。
这是我拥有的数百万个物品之一。
/* 0 */
{
"_id" : ObjectId("540449a4f59600af7d285075"),
"leagues" : [{
"name" : "Cassiopeia's Hunters",
"tier" : "GOLD",
"queue" : "RANKED_SOLO_5x5",
"entries" : [{
"playerOrTeamId" : "21893177",
"playerOrTeamName" : "JoKoksa",
"division" : "III",
"leaguePoints" : NumberLong(5),
"wins" : NumberLong(99),
"isHotStreak" : false,
"isVeteran" : false,
"isFreshBlood" : false,
"isInactive" : true,
"miniSeries" : false
}],
"id" : NumberLong(21893177) <-----------
}, {
"name" : "Kayle's Patriots",
"tier" : "BRONZE",
"queue" : "RANKED_TEAM_3x3",
"entries" : [{
"playerOrTeamId" : "TEAM-ffbaccc0-b8c0-11e2-b67a-782bcb497d6f",
"playerOrTeamName" : "EloStechers",
"division" : "II",
"leaguePoints" : NumberLong(64),
"wins" : NumberLong(9),
"isHotStreak" : false,
"isVeteran" : false,
"isFreshBlood" : false,
"isInactive" : false,
"miniSeries" : false
}],
"id" : NumberLong(21893177)
}, {
"name" : "Cassiopeia's Infiltrators",
"tier" : "BRONZE",
"queue" : "RANKED_TEAM_5x5",
"entries" : [{
"playerOrTeamId" : "TEAM-ffbaccc0-b8c0-11e2-b67a-782bcb497d6f",
"playerOrTeamName" : "EloStechers",
"division" : "II",
"leaguePoints" : NumberLong(60),
"wins" : NumberLong(11),
"isHotStreak" : false,
"isVeteran" : false,
"isFreshBlood" : false,
"isInactive" : true,
"miniSeries" : false
}],
"id" : NumberLong(21893177)
}],
"summonerId" : NumberLong(21893177),
"region" : "euw",
"updatedAt" : NumberLong(1413669289)
}
结构在"id" : NumberLong(21893177)
之后停止。你可能会忽略之后发生的事情,因为它的结构相同。先感谢您!我需要的是你如何建立表格和pk / fk,不需要数据类型,因为我会自己解决这个问题。我很难从条目创建额外的表格到详细的播放器信息。
答案 0 :(得分:0)
您可以为每个子对象创建一个单独的表。在每个表中,您将拥有一个与父对象的PK匹配的FK。
因此,在您的示例中,您将拥有一个表,其中id为PK的对象,联盟作为单独的表,其中id为PK,FK的对象ID比具有PK id的玩家表和FK的id为联盟等。