Neo4j create opposite edge

I am new to neo4j and cypher, I need to create the opposite of all the edges of the graph, but I need the opposite edges to have the same type of original edges to illustrate the opposite (a)-[:sometype]->(b)

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


I know that it is very easy to create the opposite of all edges by just pressing this command match (a)-[]->(b) create (b)-[]->(a)


but like me already said i need the created edge to have the same type of original edge thanks

+1


source to share


1 answer


According to this comment in an open question on neo4j Github, this is not possible yet.

As InverseFalcon said in this comment, you can use APOC routines to accomplish this, as described in this post from Mark Needham's blog.

Fist, set Apoc routines. After that, for example:



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: enter image description here

+2


source







All Articles