简体   繁体   English

MongoDB到Neo4j-建模

[英]MongoDB to neo4j - modelling

I have to convert this mongoDB document into a neo4j. 我必须将此mongoDB文档转换为neo4j。 This is an example of document: 这是一个文档示例:

{
    "_id" : "Atl.02",
    "official_name" : "Club Atletico de Madrid S.A.D.",
    "common_name" : "Atletico Madrid",
    "country" : "Spain",
    "started_by" : {
        "day" : 26,
        "month" : 4,
        "year" : 1903
    },
    "stadium" : {
        "name" : "Vicente Calderón",
        "capacity" : 54907
    },
    "palmarès" : {
        "La Liga" : 10,
        "Segunda Division" : 1,
        "Copa del Rey" : 10,
        "Supercopa de Espana" : 2,
        "UEFA Europa League" : 2,
        "UEFA Cup Winners Cup" : 1,
        "UEFA Super Cup" : 2,
        "FIFA Club World cup" : 1
    },
    "uniform" : "blue, white and red"
}

I create a team node: 我创建一个团队节点:

CREATE (n:team {_id:"Atl.02", official_name:"Club Atletico de Madrid S.A.D.", 
common_name:"Atletico Madrid", country:"Spain", 
started_by_day: 26, started_by_month:4, started_by_year:1903, 
uniform:"blue, white and red"})

A stadium node: 体育场节点:

CREATE (n:stadium {name:"Vicente Calderòn", capacity:54907})

The relationship between the team and the stadium: 球队与体育场之间的关系:

MATCH (n:team), (n1:stadium) WHERE n._id="Atl.02" AND
n1.name="Vicente Calderòn" CREATE n-[r:PLAYS]->n1

Here is a picture: 这是一张图片:
在此处输入图片说明

The first thing is: 第一件事是:
how to convert the information about palmarès? 怎么转换有关palmarès的信息?
I thought two possibilities: 我认为有两种可能性:
1) put this information in team node 1)将此信息放入团队节点
2) create a new node, called palmarès, and set the properties on the relationship 2)创建一个新的节点,称为palmarès,并设置关系的属性
What do you think? 你怎么看? And waht about started by information? 信息开始 Is it a good choice to put it in team node? 将其放置在团队节点中是一个好选择吗?

I recommend that you represent the individual prizes as separate nodes, since the same prize can be won by multiple teams in different years. 我建议您将各个奖项分别表示为单独的节点,因为同一奖项可以由不同年份的多个团队赢得。 Also, the queries for specific prizes would be easier to write and run quicker. 而且,对特定奖品的查询将更易于编写和运行。

For example: 例如:

(team:team {_id:"Atl.02"})-[:AWARDED {count: 10}]->(prize:Prize {name: "La Liga"})

I think putting "started_by" in the Team node is fine, but you might want to store the year/month/day as a single integer (eg, an epoch date) to make it easier to do Cypher queries involving the date. 我认为将“ started_by”放在“团队”节点中很好,但是您可能希望将年/月/日存储为单个整数(例如,纪元日期),以便更轻松地执行涉及日期的Cypher查询。

Or, if you have no convenient way to convert the year/month/day to an integer, you can combine them into an 8-character string (in year, month, and day order). 或者,如果您没有方便的方法将年/月/日转换为整数,则可以将它们组合成8个字符的字符串(按年,月和日的顺序)。 Here is an example of how to do that: 这是如何执行此操作的示例:

WITH 1993 AS year, 01 AS month, 16 AS day
RETURN
  TOSTRING(year) +
  (CASE WHEN month < 10 THEN "0" + month ELSE month END) +
  (CASE WHEN day < 10 THEN "0" + day ELSE day END)
  AS date;

The resulting date would be: "19930116". 结果date为:“ 19930116”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM