# Return node with all nodes it's in relationship but some of the related nodes meet a condition

**URL:** <https://community.neo4j.com/t/return-node-with-all-nodes-its-in-relationship-but-some-of-the-related-nodes-meet-a-condition/34451>\
**Category:** Cypher\
**Created:** [February 28, 2021, 7:44am UTC](https://community.neo4j.com/t/return-node-with-all-nodes-its-in-relationship-but-some-of-the-related-nodes-meet-a-condition/34451 "2021-02-28T07:44:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Riri](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Riri](https://community.neo4j.com/u/Riri)\
**Post date:** [February 28, 2021, 7:44am UTC](https://community.neo4j.com/t/return-node-with-all-nodes-its-in-relationship-but-some-of-the-related-nodes-meet-a-condition/34451/1 "2021-02-28T07:44:42Z")

</div>

Hi,

I'm new to Neo4j so I might be doing it the wrong way!

I have a set of nodes called Recipe. Each Recipe is in a relationship with one or more Ingredient. Now I want to search for Recipes that contain a specific list of Ingredients.

For example, if my ingredient list in search criteria is "Asparagus", it must return "Scrambled Eggs with Asparagus" which contains Asparagus but also includes other ingredients that weren't in the search criteria.

I have this Cypher query and it returns the recipe correctly:

MATCH (n:Recipe)-[r:INGREDIENTS]-\>(m:Ingredient) where (m.name = 'Asparagus') return n,collect(r),collect(m);

![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/d/9/d914ae043942da388c0f2c0925d734506895a7d2.png)

But my problem is that it only returns the Recipe node and the Asparagus node while I want it to return Recipe node _with all_ of its ingredients. I tried "exists" but it returns the same result but slower!

Does anyone know what I can do?

Any help is much appreciated 🙂

---

<div class="post-metadata">

**Author:** ![tard\_gabriel](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tard_gabriel/32/28033_2.png) [@tard\_gabriel](https://community.neo4j.com/u/tard_gabriel)\
**Post date:** [February 28, 2021, 8:28am UTC](https://community.neo4j.com/t/return-node-with-all-nodes-its-in-relationship-but-some-of-the-related-nodes-meet-a-condition/34451/2 "2021-02-28T08:28:46Z")

</div>

mi stands for main Ingredients  
si stands for second Ingredients

MATCH (mi:Ingredient)\<-[:NEEDS]-(r:Recipe) WHERE mi.name IN ['Asparagus']  
OPTIONAL MATCH (r)-[:NEEDS]-\>(si)  
RETURN r AS recipe, collect(mi.name) + collect(si.name) AS ingredients

---

<div class="post-metadata">

**Author:** ![Riri](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Riri](https://community.neo4j.com/u/Riri)\
**Post date:** [February 28, 2021, 8:46am UTC](https://community.neo4j.com/t/return-node-with-all-nodes-its-in-relationship-but-some-of-the-related-nodes-meet-a-condition/34451/3 "2021-02-28T08:46:57Z")

</div>

Perrrfect :) Thanks

I think I didn't understand what OPTIONAL MATCH does when I was reading about it. Will go back to learn it 🙂
