0

I have this code

Query query = mFirestore.collection(FirebaseManager.ADDRESS_META_SEARCH_DATA);
query = query.whereEqualTo(MetaData.COUNTRY_CODE, "se");
query = query.whereEqualTo(MetaData.COUNTRY_CODE, "us");
query = query.whereGreaterThanOrEqualTo(MetaData.NAME, text)
                .whereLessThan(MetaData.NAME, newString);
query.limit(limit);

I try to return this two countries above but Firestore throws me:

INVALID_ARGUMENT: Cannot have inequality filters on multiple properties: [country_code, name]

How can I remake this code so I can in one query get from ADDRESS_META_SEARCH_DATA collection both countries "se", and "us"

I have read the dox and I dont understand why my setup is different

citiesRef.whereEqualTo("state", "CO").whereEqualTo("name", "Denver");
citiesRef.whereEqualTo("state", "CA").whereLessThan("population", 1000000);
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Erik
  • 5,039
  • 10
  • 63
  • 119
  • 1
    The sample from the docs shows two separate queries. You're trying to create a single query that matches both countries. This type of OR query is not possible with Cloud Firestore. Also see the comments in Sam's answer here: https://stackoverflow.com/questions/47018212/implementing-or-in-firestore-query-firebase-firestore – Frank van Puffelen Feb 24 '18 at 18:34
  • So if I want to get all `ADDRESS_META_SEARCH_DATA` documents that has "se", and "us" countries I have to create two queries? one for "se" and one for "us" – Erik Feb 24 '18 at 18:42
  • I dont understand why this is an OR query, to me it´s an AND query, get-all-doc-with-us-AND-se-countries-in-them? – Erik Feb 24 '18 at 18:49
  • 1
    Let's not argue over syntax here. Fact is that you can't get `SELECT * FROM documents WHERE country IN ('se', 'us')` with a single query. I found a better dupe here: https://stackoverflow.com/questions/46632042/how-to-perform-compound-queries-with-logical-or-in-cloud-firestore – Frank van Puffelen Feb 24 '18 at 19:17

0 Answers0