Search code examples
neo4jneo4j-apoc

apoc.do.case alternative for 5


In neo4j 4.^ versions, there is the a function apoc.do.case that allows you do to follow up query depending by case As you can see here, https://neo4j.com/labs/apoc/5/overview/, that function doesn't exist (yet?) Is there any replacing function?

An use case:

CALL apoc.do.case([
  false,
  'MATCH (matched:Node {name:"random"})
  MERGE (a:Node{name:"A"})-[r:RELATION]-(matched) RETURN a AS node',
  true,
  'MATCH (matched:Node {name:"random2"})
  MERGE (b:Node{name:"B"})-[r:RELATION]-(matched) RETURN b AS node'
  ],
  'CREATE (c:Node{name:"C"}) RETURN c AS node',{})
YIELD value
RETURN value.node AS node;

Solution

  • As of Neo4j 5.0, the APOC library is divided into two parts, Core and Extended. The function apoc.do.case is part of the APOC core.

    This is the link to it's documentation.