0
votes

I have tried to create a relationship between two nodes while using Unwind on existing relationships (I am trying to migrate from a previous database)

So Links = relationships which hold the Id of each node on target and source (ID is different from the neo4j id)

The Cypher does not return any error and I do manage to add the nodes but for some reason that I cannot understand why the relationships between nodes are not getting created.

I am using this Cypher:

graphClient.Cypher
    .Unwind(graph.Links, "singleLink")
    .Match("(firstNode:Node{id: singleLink.Source , projectId: {innerProjectId}})", "(secondNode:Node{id: singleLink.Target , project: {innerProjectId}})")
    .WithParam("innerProjectId",project.Id)
    .Create("(firstNode:Node)-[:ConnectedTo{source: singleLink.Source, target: singleLink.Target}]->(secondNode:Node)")
    .ExecuteWithoutResults();           

Thanks a lot.

1
Regarding "I do manage to add the nodes": the code you provided would never attempt to create any nodes, since the CREATE clause would only be executed if the MATCH clause had already found the nodes. Are you sure you have existing Node nodes with the specified id AND projectId values? - cybersam
Yes. I am sure of it - osher elmakayes
What does the DebugQueryText look like? - Charlotte Skardon

1 Answers

0
votes

I think this is wat you want;

MATCH (n1), (n2)
WHERE ID(n1) = 1 AND ID(n2) = 2
CREATE (n1)-[r:RELATION]->(n2)