Duplicate Node

Hi All,

I am struggling with duplicate nodes, From one csv I am loading the value of employee_number and postal code. Both I am creating separate nodes.

Employee_number is having unique value though postal code is getting repeated and I want to have only unique value .
Any suggestion to handle the problem.

Check to see if you have three postal codes with "249896". Run this Cypher query:

MATCH (p:PostalCode) WHERE postalcode = "249896"
RETURN COUNT (p) as Cnt;

My suspicion is Cnt = 3

You need to add a unique constraint to zipcode (assuming your property name is zipcode as well as your node label):

CREATE CONSTRAINT ON (z:zipcode) ASSERT z.zipcode IS UNIQUE

Delete existing duplicates before applying the constraint.

The problem is likely in your load query, can you provide that so we can take a look? More than likely you are using MERGE on a pattern (not just a node) with unbound (newly-introduced) variables.

See Understanding How MERGE Works for a more detailed look at how this works, and how to get around accidentally creating duplicate nodes and/or paths.

Thank you @andrew.bowman ,@wergeland , @ameyasoft for the response . I have found the solution while inserting the data I am using merge . Below is the query and solution .

USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "file:///data/data.csv" AS line MERGE
(n:link_csn{}) WITH line, n MERGE (m:zipcode{zipcode:coalesce(line.postal_code,'NA')}) WITH
m,n MERGE (n)-[zcode:IS_RELATED]->(m) ON CREATE SET zcode.type='zipcode', zcode.weight = .02;

image