cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Using APOC for update / insert a new property like timestamp

Hi,

I would like to add to every node/relationship a property like last_update_date=timestamp()
And I want this property to be auto updated.
So I need something db triggers/

I saw APOC has similar procedures.
I registered triggers for creating nodes/relationships and it works but I can not do that
for adding/updating node/relationship's properties.

procedure propertyByKey requires name of property which I dont know yet.

And the biggest issue if I handled update on a node and then set my timestamp property
isn't a cyclic update on a node ?

Had someone similar requirement ?

Regards,
Cezary

2 REPLIES 2

Hi,

I am actually running into a similar issue.

This code works on a smaller batch of nodes to update/add properties:

MATCH (ndr:NoDelimiterRow)
WITH ndr, ndr.data AS data LIMIT 10
WITH ndr, {
	STATE_CODE_001: substring(data,0,2), // STATE_CODE_001
        STRUCTURE_NUMBER_008: substring(data,3,15), // STRUCTURE_NUMBER_008
​        ....
       TYPE_LAST_UPDATE: substring(data,434,1), // TYPE_LAST_UPDATE
       DEDUCT_CODE: substring(data,435,10) // DEDUCT_CODE
} AS record
SET ndr += record

However, when I try to drop it into apoc.periodic.iterate it is failing to update/add properties:

CALL apoc.periodic.iterate(
'
cypher runtime=slotted 
MATCH (ndr:NoDelimiterRow)
RETURN ndr, ndr.data AS data
','
SET ndr += {
  STATE_CODE_001: substring(data,0,2), // STATE_CODE_001
  STRUCTURE_NUMBER_008: substring(data,3,15), // STRUCTURE_NUMBER_008
  ...
  DEDUCT_CODE: substring(data,435,10) // DEDUCT_CODE
}
',
{batchSize:1000,parallel:false}) YIELD batches, total
RETURN batches, total

I am a bit stumped as to why the second query isn't updating/adding node properties

Hi,

I dont know how apoc.periodic.iterate works.

For me it looks weird: (return and set)
RETURN ndr, ndr.data AS data
','
SET ndr += {

maybe ?

WITH ndr, ndr.data AS data
SET ndr += {