Add constraints to neo4j node based on node property value

前端 未结 1 720
悲&欢浪女
悲&欢浪女 2021-01-29 00:55

I am adding constraints to a neo4j database using Cypher constraints and want to create a constraint which only applies to a subset of a node type.

I can create a constr

1条回答
  •  离开以前
    2021-01-29 02:01

    Instead of adding a flag property, you can just add an additional label (say, ConstrainedEntity) to Entity nodes that should be constrained. Queries can continue to use just the Entity label.

    For example:

    CREATE CONSTRAINT ON (ce:ConstrainedEntity) ASSERT EXISTS (ce.foo)
    

    To create a "flagged" Entity:

    CREATE (e:Entity:ConstrainedEntity {id: 111, foo: 'bar'})
    

    To "flag" an existing Entity:

    MATCH (e:Entity)
    WHERE e.id = 123
    SET e:ConstrainedEntity
    

    0 讨论(0)
提交回复
热议问题