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 constraint that a foo field must exist on Entity with
CREATE CONSTRAINT ON (e:Entity) ASSERT EXISTS (e.foo)
but instead, I want to constrain only nodes with a given field. e.g
CREATE CONSTRAINT ON (e:Entity {constrain_flag:true) ASSERT EXISTS (e.foo)
For example, I may have two nodes like
(e:Entity { foo: 'bar' , constrain_flag: true }) and
(e:Entity { constrain_flag: false })
I only want the constraint that e.foo must exist to apply to the Entity where constrain_flag = true, so both of these should be allowed. However,
(e:Entity { constrain_flag: false }) should throw an exception.
Is there a way to do this currently with cypher and neo4j?
Thanks in advance!