apoc.do.when
Procedure
apoc.do.when(condition Boolean, ifQuery String, elseQuery String, params Map<String, Any>)
- runs the given read/write ifQuery if the conditional has evaluated to true, otherwise the elseQuery will run.
Signature
apoc.do.when(condition :: BOOLEAN?, ifQuery :: STRING?, elseQuery = :: STRING?, params = {} :: MAP?) :: (value :: MAP?)
Input parameters
Name | Type | Default |
---|---|---|
condition |
BOOLEAN? |
null |
ifQuery |
STRING? |
null |
elseQuery |
STRING? |
|
params |
MAP? |
{} |
Usage Examples
The following will create a node with a name
property of A
, as per the ifQuery, because the predicate is true:
CALL apoc.do.when(true,
'CREATE (a:Node{name:"A"}) RETURN a AS node',
'CREATE (b:Node{name:"B"}) RETURN b AS node',
{}
)
YIELD value
RETURN value.node AS node;
node |
---|
(:Node {name: "A"}) |
The following will create a node with a name
property of B
, as per the elseQuery, because the predicate is false:
CALL apoc.do.when(false,
'CREATE (a:Node{name:"A"}) RETURN a AS node',
'CREATE (b:Node{name:"B"}) RETURN b AS node',
{}
)
YIELD value
RETURN value.node AS node;
node |
---|
(:Node {name: "B"}) |
Was this page helpful?