8

Neo4J - Copies all the relationships of another node (C # Wrapper)

 2 years ago
source link: https://www.codesd.com/item/neo4j-copies-all-the-relationships-of-another-node-c-wrapper.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Neo4J - Copies all the relationships of another node (C # Wrapper)

advertisements

i'm currently struggling with an issue an i've not found any workaround at the moment. (I'm using NEO4J C# library)

I need to merge two nodes together into a third and copy all the relationships (Type & Properties) from those two nodes to my newly created third node:

(a:Label)-[r]-()
(b:Label)-[r2]-()
(c:Label)

I've been able to properly retrieve my two first nodes & merge it into a third node that's created in the DB, but i'm struggling to copy all relationships from the two firsts nodes to the third one.

I've tried several things without success, such as:

        using (GraphClient graphClient = GetGraphClient())
        {
            var inputString = string.Format("({0}:{1})-[r]->(n), ({2}:{3})", "a", typeof(Label).Name, "b", typeof(Label).Name);
            var query = graphClient.Cypher
                    .SendQueryOnMaster()
                    .Match(inputString)
                    .Where((Label a) => a.Id == from.Id)
                    .AndWhere((Label b) => b.Id == to.Id)
                    .Create("(b)-[r2:type(r)]->(n)");
            query.ExecuteWithoutResults();
        }

Copy all relationships from one node to another might be a use-case people might have encountered :)

Is There any way to make it work ?

Thanks


Unfortunately this isn't possible in Neo4j, I imagine you've found the other posts on StackOverflow for this:

  • Move/copy all relationships to different node
  • Copy relationships of different type using Cypher
  • Neo4j Cypher: copy relationships and delete node

It'd be possible if you know the Label of the relationship at compile time, but it won't work for multiple / dynamic label types. I'm sorry that there's not a better answer to give you on this.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK