0

My database looks like this:

{
  "customers": [
    {
      "field1": "value1",
      "field2": "value2",
      "field3": "test",
      "projects": [
        "project1",
        "project2",
        "project3",
        "project4"
      ]
    },
    {
      "field1": "value1",
      "field2": "value2",
      "field3": "value3",
      "projects": [
        "project1",
        "project3"
      ]
    }
  ]
}

Now i want to get customers who contain "project1" and "project2" and these project are assigned dynamically so whereEqualTo did not seem like an option to me,so i used whereArrayContains as following:

Query query = db.collection("customers");
query = query.whereEqualTo("field3", "test");
query.whereArrayContains("projects", "project1");

It worked out fine but then i needed multiple projects to be searched so i went ahead put it like this:

Query query = db.collection("customers");
                query = query.whereEqualTo("field3", "test");
                for (int i = 0; i < selectedProjects.size(); i++) {
                    //i get a crash here:
                    query = query.whereArrayContains("projects", selectedProjects.get(i).getText());
            }

Here application crashed stating:

Invalid Query. Queries only support having a single array-contains

So this is where i am stuck now,I know that we can't put multiple whereArrayContains,then what are my options to achieve what i just explained? Why can't we have a simple IN query like sqlite here?

Mayur Gajra
  • 8,285
  • 6
  • 25
  • 41
  • There isn't really an idea solution for this. The best I could come up with is here: https://stackoverflow.com/questions/52837711/firestore-multiple-array-contains. Always feel free to [file a feature request](https://firebase.google.com/support/contact/bugs-features/) for allowing multiple `whereArrayContains`. – Frank van Puffelen Feb 23 '19 at 15:05
  • @FrankvanPuffelen It might seem like an duplicate at first but my question is how do i check for two values in single array using single `whereArrayContains`? – Mayur Gajra Feb 23 '19 at 15:10

0 Answers0