Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

c# - How to stop neo4j creating node if node already exists

I've been fiddeling around with neo4j for the last couple of days, but I keep running into one issue. Whenever I run my code it creates an entirely new node.

Issue

As seen obove there are two "SELLER" nodes and one "BUYER,SELLER" node. The node name is "Role" and I'd ideally want it to update if there is already a "Role" node and only create a new node when there is no "Role" node yet. Shown below is the query I've written in C# so far, I can't get it to stop creating new nodes. Hopefully the gods of stackoverflow can help a young lad out. haha

query = query.Merge("(role:Role {roletype: $newRoleValue})")
                    .Set("role = $newRole")
                    .WithParam("newRole", new { Name = newTenderVersion.Organization.Role.ToString() })
                    .WithParam("newRoleValue", newTenderVersion.Organization.Role.ToString())
                    .Merge($"(organization)-[:HAS_ROLE]->(role)");

===== EDIT:

query = query.Merge("(role:Role {roleType: $newRoleValue})")
                    .WithParam("newRoleValue", newTenderVersion.Organization.Role.ToString())
                    .Merge($"(organization)-[:HAS_ROLE]->(role)");

So I've figured out how to stop the node duplication, now the question remains. How do I make sure that if an organization is only a SELLER, it will delete its BUYER nodes.

question from:https://stackoverflow.com/questions/65950336/how-to-stop-neo4j-creating-node-if-node-already-exists

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...