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