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?