How to collect results is Neo4J?

I will explain steps:

  • WITH post, rule, collect(DISTINCT category.name) AS categories will return:
    post1, rule1, ['PARENT']
    post1, rule2, ['SCHOOL']
    post1, rule3, ['TOPICS']
    post1, rule4, ['GRADE1', 'GRADE3']

  • WITH post, collect(categories) AS rule_cats will return:
    post1, [['PARENT'], ['SCHOOL'], ['TOPICS'], ['GRADE1', 'GRADE3']]

  • WHERE all(x IN rule_cats WHERE any(n IN x WHERE n IN $allowedCategories)) will check for each element of rule_cats if at least one of the category is in $allowedCategories :slight_smile:

I hope it's more clear now :slight_smile:

3 Likes