Create unique node based on properties via Cypher

141 views
Skip to first unread message

Rohit Kumar

unread,
Aug 20, 2012, 10:12:16 AM8/20/12
to ne...@googlegroups.com
With CREATE, you can create a node with properties. Is it possible to uniquely create a node with certain properties that must be unique, with Cypher (with CREATE UNIQUE, perhaps)?

Thanks,
Rohit Kumar

Peter Neubauer

unread,
Aug 20, 2012, 10:19:59 AM8/20/12
to ne...@googlegroups.com
You cannot yet, but that is the exact trajectory for CREATE UNIQUE :)

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Wanna learn something new? Come to @graphconnect.
> --
>
>

Rohit Kumar

unread,
Aug 21, 2012, 2:03:23 PM8/21/12
to ne...@googlegroups.com
Ah, okay. What about this: I have a node with N a keyword property: keyword = "cars". Is there a way to use create unique such that I can connect other nodes to this node if it exists?

So:

Bob----has_keyword---->(N {keyword: "planes"}).

Now, if other people have the same keyword, I want them to be able to connect to the same keyword node that bob is connected to, rather than creating a new duplicate keyword node. Something like:
start n = node(5) create unique n-[:INTERESTED_IN]->(kwn {keyword: "planes"});

This query creates a new node though. So it is possible with create unique, or is there an alternate query that I can use?

Thanks,
Rohit

Michael Hunger

unread,
Aug 21, 2012, 6:57:45 PM8/21/12
to ne...@googlegroups.com
What you would do in this case is to connect the keywords nodes to a "category"-node.

start keywords=node(1), n = node(5) create unique n-[:INTERESTED_IN]->(kwn {keyword: "planes"})<-[:IS_KEYWORD]-keywords;

In some future that will also work with index-lookups.

Michael

--
 
 

Reply all
Reply to author
Forward
0 new messages