1
votes

I have a requirement to auto generate sequence numbers when inserting nodes into neo4j db, this sequence # will be like an id to the node and can be used to generate external url's to access that node directly from the UI.

This is similar to the auto generation of sequence property in mysql, how can we do this in neo4j via Cypher ? I did some research and found these links

Generating friendly id sequence in Neo4j

http://neo4j.com/api_docs//1.9.M05/org/neo4j/graphdb/Transaction.html

However these links are useful when I'm doing this programatically in transactional mode, in my case it's all using Cypher REST API.

Pls advise.

Thanks,

Deepesh

2

2 Answers

7
votes

You can use MERGE to mimic sequences:

MERGE (s:Sequence {name:'mysequenceName'})
ON CREATE s.current = 0
ON MATCH s.current=s.current+1
WITH s.current as sequenceCounter
MATCH .... <-- your statement continues here
0
votes

If your unique ID does not need to be numeric nor sequential, you can just generate and use a GUID whenever you want to create a node. You have to do this programmatically, and you should pass the value as a parameter, but there should be good libraries for GUID generation in all languages and for all platforms.