cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 1: replicate users.

APOC procedure to Trigger an ID

Andrea-Cavallo
Node Link

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 ?

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

1 ACCEPTED SOLUTION

Bennu
Graph Fellow

Hi @Andrea-Cavallo

You may like something like:

CALL apoc.trigger.add('create-event-gen-id',"UNWIND $createdNodes AS e
MATCH(n:User) 
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.

Bennu

View solution in original post

1 REPLY 1

Bennu
Graph Fellow

Hi @Andrea-Cavallo

You may like something like:

CALL apoc.trigger.add('create-event-gen-id',"UNWIND $createdNodes AS e
MATCH(n:User) 
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.

Bennu