apoc.do.case

Procedure

apoc.do.case(conditionals [Any], elseQuery String, params Map<String, Any>) - for each pair of conditional queries in the given list, this procedure will run the first query for which the conditional is evaluated to true. If none of the conditionals are true, the ELSE query will run instead.

Signature

apoc.do.case(conditionals :: LIST? OF ANY?, elseQuery =  :: STRING?, params = {} :: MAP?) :: (value :: MAP?)

Input parameters

Name Type Default

conditionals

LIST? OF ANY?

null

elseQuery

STRING?

params

MAP?

{}

Output parameters

Name Type

value

MAP?

Usage Examples

The following will create a node with a name property of B, because that’s the first of the conditionals to evaluate to true:

CALL apoc.do.case([
  false,
  'CREATE (a:Node{name:"A"}) RETURN a AS node',
  true,
  'CREATE (b:Node{name:"B"}) RETURN b AS node'
  ],
  'CREATE (c:Node{name:"C"}) RETURN c AS node',{})
YIELD value
RETURN value.node AS node;
Table 1. Results
node

(:Node {name: "B"})

The following will create a node with a name property of C, as per the elseQuery, because all conditionals evaluate to false:

CALL apoc.do.case([
  false,
  'CREATE (a:Node{name:"A"}) RETURN a AS node',
  false,
  'CREATE (b:Node{name:"B"}) RETURN b AS node'
  ],
  'CREATE (c:Node{name:"C"}) RETURN c AS node',{})
YIELD value
RETURN value.node AS node;
Table 2. Results
node

(:Node {name: "C"})