Neo4j: Assign unique values to all nodes matching query
I want to implement a unique ID property on all nodes in my database but need to apply it to existing data. I'm using Ruby to perform generate the IDS and then running the Cypher query from there. I want to avoid one query to find nodes missing the property, another to set the property on each node individually, since that would require total_nodes + 1 queries. Initially, I was thinking I could do something like this: MATCH (n:`#{label}`) WHERE NOT HAS(n.my_id) SET n.my_id = '#{gen_method}' RETURN DISTINCT(true) Of course, this wouldn't work because it would call gen_method once in Ruby and