If your document looks like this:
$user (document)
|
--- Username: "Kennedy"
|
--- Age: 20
|
--- Gender: "male"
|
--- Country: "USA"
|
--- City: "NY"
The follwing logic makes sense to be used:
if(country==countryA || country == countryB)
As it means that you want to perform an OR query. This can be achieved in Java up to ten elements using:
colRef.whereIn("Country", Arrays.asList("countryA", "countryB"));
However, there is a constraint. You cannot add another:
.whereIn("City", Arrays.asList("CityA", "CityA"));
Since you can use at most one whereIn
clause per query. To solve this, you have to use the first query and filter the cities in the client.
Back to your initial queries:
colRef.whereEqualTo("countryA",country).get();
colRef.whereEqualTo("countryB",country).get();
colRef.whereEqualTo("CityA",city).get();
colRef.whereEqualTo("CityB",city).get();
I see that you are using different fields for "countryA" and "countryB", as well as for "CityA" and "CityB", ending in having a schema that looks like this:
$user (document)
|
--- Username: "Kennedy"
|
--- Age: 20
|
--- Gender: "male"
|
--- countryA: "A"
|
--- CityA: "A"
|
--- CountryB: "B"
|
--- CityB: "B"
This also means that those queries don't help you perform an OR operation. So most likely you should consider using the first database schema and perform a whereIn()
query and filter the results in memory.