How do you select a random item across multiple documents and then refer back to the selected document's items?

Hi, I am relatively new to this community. Have learnt the basics but still learning how to apply it all. I want to be able to randomly select a meal from my firebase database and then choose an appropriate meat to align it with but am struggling to do so. Each meal is it’s own document as it has multiple fields within it including Meal_Name, Meat, Carb type (eg. Rice, noodles, pasta), and cooking effort level (low, medium, hard).

So far I created a data variable collection called mealCollection and was able to successfully generate a random meal name using this formula: PICK_ITEM(FLATTEN(MAP(data.mealCollection,item.fields.Meal_Name.stringValue)),RANDOM_INTEGER_BETWEEN(0,pageVars.totalMealsCounter-1))

Essentially the above pulls all the Meal_Name items from each document into a list and randomly picks a meal from that list. It might return a result such as “Stir Fry” which is one of the meal names currently in my data.

I want that random meal to also include the meat being used in front of it. In my database I have set up the Meat item as an array as certain meals like a Stir Fry can be done with multiple meats (eg. Chicken or Beef) so I want it to generate something like “Chicken Stir Fry”. From what I have done above, it compiles all the meal names in a new list and to my knowledge I have no idea how to then reference back to the Meat item data. Any thoughts on how I could approach this? Or maybe restructure it?

Ultimately I want to get to the user being able to select their preferences up front whether they feel like a particular meat, carb, or effort level (can leave blank) and then generate a random answer from the data that fits the preferences. But that might be a few steps later.

For someone thats new you seem to really know hour stuff! I think there are a few options for this. Depedning on how many types of food and ingredients, you could do a few things.

First, you could search specificially for the records you need (I have a video that shows this at a very high level here): How To Clean API Responses In Appgyver - YouTube

Additionally, If you have a smaller number of ingredients or entrees you could try to hard code different areas of the app. For example, in the video below around the 30 minute mark I show a ticket management app. This has limited categories that are hard coded (1-5) and each has a different page. Then at 34:48 I show how to order is decending order. Instead of ordering this way, you could try to order or sort by the values (help article on this function here Order - list).

Video: How To Clean API Responses In Appgyver - YouTube