将 MongoDB 转换为 neo4j 图中的两个集合
Convert a MongoDB with two collections in a neo4j graph
我完成了 Mongo 数据库的创建。它由两个系列组成:
1. team
2. coach
我给你举了这些集合中包含的文件的例子:
这是团队文档:
{
"_id" : "Mil.74",
"official_name" : "Associazione Calcio Milan S.p.A",
"common_name" : "Milan",
"country" : "Italy",
"started_by" : {
"day" : 16,
"month" : 12,
"year" : 1899
},
"stadium" : {
"name" : "Giuseppe Meazza",
"capacity" : 81277
},
"palmarès" : {
"Serie A" : 18,
"Serie B" : 2,
"Coppa Italia" : 5,
"Supercoppa Italiana" : 6,
"UEFA Champions League" : 7,
"UEFA Super Cup" : 5,
"Cup Winners cup" : 2,
"UEFA Intercontinental cup" : 4
},
"uniform" : "black and red"
}
这是教练文档:
{
"_id" : ObjectId("556cec3b9262ab4f14165fcd"),
"name" : "Carlo",
"surname" : "Ancelotti",
"age" : 55,
"date_Of_birth" : {
"day" : 10,
"month" : 6,
"year" : 1959
},
"place_Of_birth" : "Reggiolo",
"nationality" : "Italian",
"preferred_formation" : "4-2-3-1",
"coached_Team" : [
{
"team_id" : "RMa.103",
"in_charge" : {
"from" : "26/june/2013",
"to" : "25/may/2015"
},
"matches" : 119
},
{
"team_id" : "PSG.00",
"in_charge" : {
"from" : "30/dec/2011",
"to" : "24/june/2013"
},
"matches" : 77
},
{
"team_id" : "Che.11",
"in_charge" : {
"from" : "01/july/2009",
"to" : "22/may/2011"
},
"matches" : 109
},
{
"team_id" : "Mil.74",
"in_charge" : {
"from" : "07/nov/2001",
"to" : "31/may/2009"
},
"matches" : 420
}
]
如您所见,我使用了一个标准化模型:每个教练都有一组执教过的球队。
我想将此 Mongo 数据库转换为图形数据库,特别是 Neo4j;我的目需要两个查询,而不是在 neo4j 中它足以遵循关系 ).
我在使用 Gremlin 自动将 mongo 文档集合转换为 Neo4j 图形的论坛上发现 this guide。
问题是指南只谈论一个集合。
那么,是否可以从我的 mongo 数据库(有两个集合)开始自动生成 neo4j 图,或者我必须创建图 "by hand"?
Gremlin 是一种用于处理图形的领域特定语言,但它基于 Groovy,因此您可以有效地拥有您真正想要做的任何事情的所有灵活性。换句话说,您可以用一个 MongoDB 集合做的事情用两个(或您拥有的任意多个集合)也可以轻松完成。这就是另一个 answers:
中引用的博客 post 的要点
http://thinkaurelius.com/2013/02/04/polyglot-persistence-and-query-with-gremlin/
Gremlin 是一种将数据转换为图形形式的出色语言,无论其源格式是什么。我认为您会首先将所有团队作为顶点加载,然后遍历您的教练,在您进行时为他们的相关团队创建教练顶点和边。
我还要补充一点 "automatic" 关于 Gremlin。这并不是说您告诉 Gremlin 您在 MongoDB 中有数据并将其转换为图表。您必须编写 Gremlin 来告诉它您希望如何将 MongoDB 数据转换为图表。
我完成了 Mongo 数据库的创建。它由两个系列组成:
1. team
2. coach
我给你举了这些集合中包含的文件的例子:
这是团队文档:
{
"_id" : "Mil.74",
"official_name" : "Associazione Calcio Milan S.p.A",
"common_name" : "Milan",
"country" : "Italy",
"started_by" : {
"day" : 16,
"month" : 12,
"year" : 1899
},
"stadium" : {
"name" : "Giuseppe Meazza",
"capacity" : 81277
},
"palmarès" : {
"Serie A" : 18,
"Serie B" : 2,
"Coppa Italia" : 5,
"Supercoppa Italiana" : 6,
"UEFA Champions League" : 7,
"UEFA Super Cup" : 5,
"Cup Winners cup" : 2,
"UEFA Intercontinental cup" : 4
},
"uniform" : "black and red"
}
这是教练文档:
{
"_id" : ObjectId("556cec3b9262ab4f14165fcd"),
"name" : "Carlo",
"surname" : "Ancelotti",
"age" : 55,
"date_Of_birth" : {
"day" : 10,
"month" : 6,
"year" : 1959
},
"place_Of_birth" : "Reggiolo",
"nationality" : "Italian",
"preferred_formation" : "4-2-3-1",
"coached_Team" : [
{
"team_id" : "RMa.103",
"in_charge" : {
"from" : "26/june/2013",
"to" : "25/may/2015"
},
"matches" : 119
},
{
"team_id" : "PSG.00",
"in_charge" : {
"from" : "30/dec/2011",
"to" : "24/june/2013"
},
"matches" : 77
},
{
"team_id" : "Che.11",
"in_charge" : {
"from" : "01/july/2009",
"to" : "22/may/2011"
},
"matches" : 109
},
{
"team_id" : "Mil.74",
"in_charge" : {
"from" : "07/nov/2001",
"to" : "31/may/2009"
},
"matches" : 420
}
]
如您所见,我使用了一个标准化模型:每个教练都有一组执教过的球队。
我想将此 Mongo 数据库转换为图形数据库,特别是 Neo4j;我的目需要两个查询,而不是在 neo4j 中它足以遵循关系 ).
我在使用 Gremlin 自动将 mongo 文档集合转换为 Neo4j 图形的论坛上发现 this guide。
问题是指南只谈论一个集合。
那么,是否可以从我的 mongo 数据库(有两个集合)开始自动生成 neo4j 图,或者我必须创建图 "by hand"?
Gremlin 是一种用于处理图形的领域特定语言,但它基于 Groovy,因此您可以有效地拥有您真正想要做的任何事情的所有灵活性。换句话说,您可以用一个 MongoDB 集合做的事情用两个(或您拥有的任意多个集合)也可以轻松完成。这就是另一个 answers:
中引用的博客 post 的要点http://thinkaurelius.com/2013/02/04/polyglot-persistence-and-query-with-gremlin/
Gremlin 是一种将数据转换为图形形式的出色语言,无论其源格式是什么。我认为您会首先将所有团队作为顶点加载,然后遍历您的教练,在您进行时为他们的相关团队创建教练顶点和边。
我还要补充一点 "automatic" 关于 Gremlin。这并不是说您告诉 Gremlin 您在 MongoDB 中有数据并将其转换为图表。您必须编写 Gremlin 来告诉它您希望如何将 MongoDB 数据转换为图表。