neo4j create the opposite edge

岁酱吖の 提交于 2019-12-11 07:19:29

问题


i am new to neo4j and cypher , i need to create the opposite of all the edges of the graph but i need that the opposites edges to have the same type of the original edges
for illustration the opposite of (a)-[:sometype]->(b) would be (b)-[:sometype]->(a)
i know that it is very easy to create the opposite of all the edges by just tapping this command match (a)-[]->(b) create (b)-[]->(a)
but as i have already said i need the created edge to have the same type of the original edge thank you


回答1:


According to this comment in an open question in neo4j's Github this is not possible yet.

As said by InverseFalcon in this comment, you can use APOC Procedures to achieve this goal as described in this post from Mark Needham blog.

Fist, install Apoc Procedures. After this, e.g.:

CREATE (a)-[:sometype]->(b)

//Match...
MATCH (a)-[r]->(b)
WITH r, a, b
// and use apoc.create.relationship to achieve your goal...
CALL apoc.create.relationship(b, TYPE(r), {}, a) YIELD rel
RETURN rel

Tested here:



来源:https://stackoverflow.com/questions/43594138/neo4j-create-the-opposite-edge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!