Lomo
Lomo

Reputation: 89

NEO4J / Cypher: Create Node if a collection only has false result

i have a COLLECT with true or false based on a validation query and i want to create one node if every result in the collection is false. How do i filter the Collection for this specific result?

WITH COLLECT(DISTINCT(...))

[true] = Nothing happens

[false,true] = Nothing happens

[false] = Create new node

Upvotes: 0

Views: 67

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30407

You can use an all() or none() list predicate which will allow you to test every element of the list and return the appropriate boolean value.

WITH COLLECT(DISTINCT(...)) as testList
WHERE all(val in testList WHERE val = false)
CREATE ...

Keep in mind that this will return true for an empty list, so you may want to add an additional predicate: AND size(testList) > 0

Upvotes: 2

Related Questions