- Why do you want to reuse auto-generated IDs!?
- There is not an efficient mechanism for finding unused numbers in an index, so if you're trying to ensure sequential IDs for some other purpose, you should probably do that other thing a different way.... what is that other thing you're trying to do?
Here's two great posts about auto-generating IDs, that dive pretty deep, and offer some suggestions. IMO, don't use the built-in id. It is not stable, and can change, and can cause severe problems in queries where you need to delete anything.
TL;DR:
See: Neo4j Docs: Cypher Schema
CREATE CONSTRAINT ON (e:Event) ASSERT e.id IS UNIQUE;
CREATE INDEX ON :Event(id);
MATCH (e:Event) SET e.id = id(e);
See: apoc.create.uuid and apog.trigger
You could potentially use apoc.trigger
to auto-generate a UUID on create, if it is really necessary, but it's better to generate in your script when you use a CREATE
statement.
CALL apoc.trigger.add('create-event-gen-id',"UNWIND {createdNodes} AS e set e.id=apoc.create.uuid()", {phase:'after'});
My answer on here includes code-samples to auto-generate UUIDs, and make them unique:
This discussion includes many different approaches to the problem: