Posts

Showing posts with the label APOC

Updating a Property on a Highly Accessed Node

There may be a time where many user sessions attempt to update the same property on the same node. Unlikely, but possible. This may be a 'sequence' node, where you're keeping track of an increasing identifier, a sort of autoincrement. How can you be, almost, certain that your CYPHER statement will not be blocked by another session updating the node property at that exact time? Assume the sequence node: CREATE (s:Sequences {counterToIncrement: 0}) Then call the following CYPHER MATCH (s:Sequences) CALL apoc.atomic.add(s,'counterToIncrement',1,10) YIELD newValue as seq RETURN seq This will attempt to add 1 to the sequence property 'counterToIncrement' , and will attempt up to 10 times if the property is locked, and finally the new value of 'counterToIncrement' is yielded and returned. From a post : https://community.neo4j.com/t5/neo4j-graph-platform/integer-sequence-generator-in-neo4j-apoc/td-p/19403  

Property DataType - apoc.meta.type

Node Properties in Neo4j. A property can be of any datatype even within nodes of the same label. Nodes have no fixed schema as with the RDBMS where most notions of data storage are formed and 'best practice' is enforced.  Properties themselves do not have types, but the values they hold do. However, you can have a property, X which could be assigned a string value or a numeric value. There is no enforcement of typing for a property. Of course, it would not (always) make sense to assign a property different type values in your graph. So, just what datatype is the property? Trusty APOC has a function for that. WITH [true, 42, 'foo', 1.2] AS data UNWIND data as value RETURN apoc.meta.type(value) So, just what datatype is the property? "BOOLEAN" "INTEGER" "STRING" "FLOAT" You can use this function in MATCHES on nodes in your system where properties are unknown at runtime. MATCH (n:MyNode) RETURN apoc.meta.type(n.MyProperty)