If I have a simple collection such as:
Fruits:
Banana:
title: \"Banana\"
vitamins: [\"potassium\",\"B6\",\"C\"]
Apple:
title: \"Apple\"
vitam
It has been commented upon, but the accepted answer isn't feasible if your query requires you to create a composite index, because it'll likely lead to your count of composite indexes quickly reaching the limit of 200. It's hacky, but the best solution I can think of is to store - in some kind of guaranteed order, e.g. alphabetically - an array of every combination of vitamin for a given fruit, each combination being concatenated as a string. For example, as bananas contain B6, C, and potassium, an array of vitamin combinations for bananas would be:
B6B6||CB6||C||potassiumB6||potassiumCC||potassiumpotassiumThen, if your user was searching for every fruit that contains BOTH B6 AND potassium, your query would be:
db.collection("Fruits").where("vitamins", "array-contains", "B6||potassium")