How to Merge with unique constraints and conflicting matches

(Foysal Osmany) #1

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})
    u.created = prospect.created,
    u.domain = prospect.domain, =, =,
    u += prospect.fields
    u += prospect.fields

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

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?

(Tom) #2

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 ...