Neo4j中链接列表的字段数组

Neo4j中链接列表的字段数组,neo4j,cypher,graph-databases,Neo4j,Cypher,Graph Databases,我试图根据数组中的数据创建一系列链接的节点。我有一个头部节点,我想在其中附加链接节点,但是,当使用“展开”或“FOREACH”时,我最终将头部节点单独链接到每个链接节点,而不是像链接列表一样 $locations包含一个对象数组,其中包含创建所需节点所需的信息。我无法在之前创建节点并进行收集,因为我没有唯一的方法获取我刚刚创建的特定类型的节点,因为它应该基于它们链接到的头节点 CREATE (head:Game:Trail{ GUID: apoc.create.uuid(), creat

我试图根据数组中的数据创建一系列链接的节点。我有一个头部节点,我想在其中附加链接节点,但是,当使用“展开”或“FOREACH”时,我最终将头部节点单独链接到每个链接节点,而不是像链接列表一样

$locations包含一个对象数组,其中包含创建所需节点所需的信息。我无法在之前创建节点并进行收集,因为我没有唯一的方法获取我刚刚创建的特定类型的节点,因为它应该基于它们链接到的头节点

CREATE (head:Game:Trail{
  GUID: apoc.create.uuid(),
  creationDate: datetime(),
  title: $title,
  description: $description
})
选择1

FOREACH (trail IN $locations |
  CREATE (a:Pin:Trail{ GUID: apoc.create.uuid(), creationDate: datetime(), text: trail.hint.text, lat: trail.lat, lng: trail.lng })
  MERGE (head)-[:LEADS_TO]->(a)
  MERGE (a)<-[r1:IS_ABOUT]-(image:Image:Media{GUID: apoc.create.uuid(), filename: trail.blobFile.filename})
    ON CREATE SET a.imageURL = 'https://......../' + image.GUID + '.' + trail.blobFile.extension
  SET head = a
)
输出应为这种格式

(头部)-[LEADS_TO]->(节点)-[LEADS_TO]->(节点2)

但是,我尝试过的两个选项都会产生相同的输出,最终的输出格式如下:

(头部)-[LEADS\u TO]->(节点),(头部)-[LEADS\u TO]->(节点2)\


非常感谢您的帮助!谢谢

我今天过得有点像APOC——可能有一种密码方式可以做到这一点,但给出一些虚拟数据:

:param locations => [
    { hint: { text: 'first stop' }, lat: 1, long: 1 },
    { hint: { text: 'second stop' }, lat: 2, long: 1 },
    { hint: { text: 'last stop' }, lat: 3, long: 1 }
]
以下APOC重密码块将创建节点,使用
APOC.nodes.link
从节点创建链接列表,然后将链中的第一个节点链接到“head”节点:

CREATE (head:Game:Trail {
    GUID: apoc.create.uuid(),
    creationDate: datetime(),
    title: 'Some title',
    description: 'Some description'
})
WITH head, [trail in $locations | { GUID: apoc.create.uuid(), creationDate: datetime(), text: trail.hint.text, lat: trail.lat, long: trail.long }] as trails
CALL apoc.create.nodes(['Pin', 'Trail'], trails) YIELD node
WITH head, collect(node) as nodes
CALL apoc.nodes.link(nodes, 'LEADS_TO')
WITH head(nodes) as firstNode, head
MERGE (head)-[:LEADS_TO]->(firstNode)

CREATE (head:Game:Trail {
    GUID: apoc.create.uuid(),
    creationDate: datetime(),
    title: 'Some title',
    description: 'Some description'
})
WITH head, [trail in $locations | { GUID: apoc.create.uuid(), creationDate: datetime(), text: trail.hint.text, lat: trail.lat, long: trail.long }] as trails
CALL apoc.create.nodes(['Pin', 'Trail'], trails) YIELD node
WITH head, collect(node) as nodes
CALL apoc.nodes.link(nodes, 'LEADS_TO')
WITH head(nodes) as firstNode, head
MERGE (head)-[:LEADS_TO]->(firstNode)