0

Let's say, that in a document in field studentsI have a field, subjects,which is an array of strings that could be set up as follows: subjects = ["Computer Science,"Mathematics","Additional Mathematics"]

And another array subjectsToCompare = ["Computer Science","Mathematics"]

How do I construct a query that returns all documents where the subjects field contains at least ALL the values in subjectsToCompare? It may contain other values, but it MUST contain all the values in subjectsToCompare.

Tried using "array-contains" and "in" but none of them give the desired behaviour.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 2
    Firestore doesn't have such a query. Consider using a different way of structuring your data to at least make it possible, as shown in the duplicate. – Doug Stevenson Jul 15 '23 at 21:19
  • @DougStevenson Thank you. I have tried modifying my data structure as recommended. But subjectsToCompare could be of any length, whereas in the duplicate questions the length is known, and hence you can chain multiple where queries. How do I do so, if I do not know the length of the array? – WasayAK117 Jul 16 '23 at 12:39
  • That sounds like https://stackoverflow.com/questions/48036975/firestore-multiple-conditional-where-clauses – Doug Stevenson Jul 16 '23 at 12:44

0 Answers0