0

Say I have a collection of recipes that match this format:

{
  title: "a recipe",
  ingredients: [
    {
      description: "sugar",
      amount: "1 cup"
    },
    {
      description: "flour",
      amount: "2 cups"
    }
  ] 
}

If given an array such as ["sugar", "butter"], what is the best way to return all recipes that have an ingredient whose description is in the given array?

1
  • Give an example and what have you tried! Commented Dec 5, 2013 at 20:44

1 Answer 1

1

MongoDB unwinds the arrays while querying. So this query ought to do it.

{'ingredients.description':{$in:["sugar", "butter"]}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.