my query below returns "Success" string if node n successfully matched. In case it was not matched, the output is "(no changes, no records)" while I expect the query to return "Failure" string. I guess this is to do with node n not existing and therefore 'with value.rslt' is also not existing which returns nothing. How can I get "Failure" return in case node n not matched? Thank you
match(n:device) where n.nid = 'non-existing' CALL apoc.do.case( [ n is not null, "return 'Success' as rslt" ], "return 'Failure' as rslt", {n:n} ) yield value with value.rslt as rslt return rslt
You can do OPTIONAL MATCH, it returns NULL when there are no nodes matching the condition.
OPTIONAL MATCH
NULL
OPTIONAL MATCH (n:device) WHERE n.nid = 'non-existing' RETURN DISTINCT CASE n WHEN NULL THEN 'Failure' ELSE 'Success' END
1.4m articles
1.4m replys
5 comments
57.0k users