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.

How to Merge with unique constraints and conflicting matches

I have an unique constraints on a node

ON ( business:Business ) ASSERT business.domain IS UNIQUE

I am trying to run query

MERGE (u:UserPublishers {domain: prospect.domain})
ON CREATE SET
    u.id = prospect.id,
    u.created = prospect.created,
    u.domain = prospect.domain,
    u.name = prospect.name,
    u.email = prospect.email,
    u += prospect.fields
ON MATCH SET
    u += prospect.fields

When I run this I am getting error like
Node(10745858) already exists with labelBusinessand propertydomain= 'adinject.com'

Is there any other way to achieve the goal

  • when the domain is same it will merge with existing and update the other properties?
  • when the domain is null is there any way to skip it?
  • using apoc periodic iterate is there any way so that it will work partially instead of run it in transaction?
1 REPLY 1

Since the unique constraint is on label Business and property domain, can you do the MERGE also on that label (I'm assuming UserPublishers is a secondary label) ? Since there is no constraint on UserPublishers the MERGE is not doing what you think it's doing ...

Regards,
Tom