How to create unique constraint involving multiple properties in Neo4J

后端 未结 3 826
名媛妹妹
名媛妹妹 2020-12-10 11:02

I know I can create a unique constraint on a single property with Cypher like CREATE CONSTRAINT ON (p:Person) ASSERT p.name IS UNIQUE. But I was wondering wheth

3条回答
  •  醉话见心
    2020-12-10 11:25

    As of neo4j version 3.3 there is a constraint called NODE KEY which can be used for uniqueness across multiple properties.

    From the documentation:

    To create a Node Key ensuring that all nodes with a particular label have a set of defined properties whose combined value is unique, and where all properties in the set are present

    Example Query

    CREATE CONSTRAINT ON (n:Person) ASSERT (n.firstname, n.surname) IS NODE KEY
    

提交回复
热议问题