APOC procedure to Trigger an ID

Hello guys,
which is the correct APOC procedure to Trigger an ID and (Increment it +1) every time I call a create?

Assuming User has an ID - my idea is to increment using ID and not UUID, I know maybe is not performant but I have to.

The perfect thing to me should be triggering the ID but as the MAX-ID ( something like maxId + 1 )

CALL apoc.trigger.add('create-event-gen-id',"UNWIND {createdNodes} AS e
MATCH (n:User) 
 set e.ID=e.ID + 1", {phase:'after'});

Can you help me ? :grinning:

Thank you, for you're time.
I really appreciate!!

Hi @Andrea-Cavallo

You may like something like:

CALL apoc.trigger.add('create-event-gen-id',"UNWIND $createdNodes AS e
with e MAX(n.ID) as maxId 
Set e.ID = maxId + 1", {phase:'before'})

It's important to notice that if you create somethin' new. You don't see the property inside the CREATE response. You need to execute a MATCH after it in order to retrieve the info.


1 Like