cypher - Reliable (auto)incrementing identifiers for all nodes/relationships in Neo4j -
i'm looking way generate unique identifiers nodes/relationships in neo4j, based on incrementing counter (not big long uuids).
the internal ids maintained neo4j engine known not reliable outside references.
a solution comes close the code proposed in question, doesn't work when single create
clause creates multiple new nodes:
// unique id merge (id:uniqueid{name:'person'}) on create set id.count = 1 on match set id.count = id.count + 1 id.count uid // create new node attached every existing :something node match (n:something) create (:somethingrelated {id:uid}) -[:rel]-> (n)
when there multiple (n:something)
, every newly created (:somethingrelated)
share same id. there way around this, using cypher?
try allocate block of ids:
// collect nodes connect match (n:crew) collect(n) nodes merge (id:uniqueid { name:'person' }) // reserve id-range set id.count = coalesce(id.count,0)+ size(nodes) nodes, id.count - size(nodes) base // each index unwind range(0,size(nodes)-1) idx // node, compute id nodes[idx] n, base +idx id create (:somethingrelated { uid:id })-[:rel]->(n)
Comments
Post a Comment