Search code examples
neo4jcypherapoc

Neo4j pure Cypher alternative for apoc.coll.intersection


In order to find an intersection of two arrays, I use the following APOC call:

apoc.coll.intersection($detailedCriterionIds, childD.detailedCriterionIds) 

Could you please show how to implement the same with pure Cypher without APOC help? Thanks!


Solution

  • You can use list comprehension.

    [x IN list1 WHERE x IN list2 | x]
    

    In this example, you iterate over all elements in list1 and only keep those elements that are also in list2