Are you sure these are all the queries you use? MERGE has this very common place where it combines everything that you give it. So what people expect:
neo4j-sh (?)$ MERGE (mac:MacAddress { Value: "D857EFEF1CF6" }); +-------------------+ | No data returned. | +-------------------+ Nodes created: 1 Properties set: 1 Labels added: 1 1650 ms neo4j-sh (?)$ MERGE (mac:MacAddress { Value: "D857EFEF1CF6" }); +--------------------------------------------+ | No data returned, and nothing was changed. | +--------------------------------------------+ 17 ms neo4j-sh (?)$ match (mac:MacAddress { Value: "D857EFEF1CF6" }) return count(mac); +------------+ | count(mac) | +------------+ | 1 | +------------+ 1 row 200 ms
So far so good. This is what we expect. Now see this:
neo4j-sh (?)$ MERGE (mac:MacAddress { Value: "D857EFEF1CF6" })-[r:foo]->(b:SomeNode {label: "Foo!"}); +-------------------+ | No data returned. | +-------------------+ Nodes created: 2 Relationships created: 1 Properties set: 2 Labels added: 2 178 ms neo4j-sh (?)$ match (mac:MacAddress { Value: "D857EFEF1CF6" }) return count(mac); +------------+ | count(mac) | +------------+ | 2 | +------------+ 1 row 2 ms
Wait, WTF is here? We again indicated only the same MAC address, why is the duplicate created?
The MERGE documentation indicates that "MERGE will not partially use existing models - its all or nothing, if partial matches are needed, this can be achieved by splitting the template into multiple MERGE clauses." So when we run this MERGE path, the whole path does not exist yet, it creates everything in it, including the duplicate MAC address of the node.
Often questions arise about duplicated nodes created by MERGE , and 99 times out of 100, this is what happens.
source share