0

I have a recyclerview using Firestore Recyclerview Adapter, Now I want to show the list by using OR query. For example I want to show the list which are either in "Pending" state OR "Assigned" state using query. I know firestore doesn't have OR query inbuilt but I want to achieve this anyhow. Any alrernative solution.

I have stored 4 state in firestore db : Pending, Assigned, Accepted and Completed. Only want to show pending or assigned

Below is my code:

    Query query = requestVehiclesCollectionReference
            .whereEqualTo("clientId", id)
     // show list which are in Pending state or Assigned state
            .whereEqualTo("status", "Pending")
            .orderBy("createdAt", Query.Direction.DESCENDING);


    FirestoreRecyclerOptions<Item> options = new 
    FirestoreRecyclerOptions.Builder<Item>()
            .setQuery(query, Item.class)
            .build();
Fortray
  • 133
  • 1
  • 1
  • 8

1 Answers1

0

Firestore doesn't support queries with OR conditions. See:

The common workaround is to use multiple queries (one for each condition) and merge the results in your application code.

FirebaseUI's adapters show data from a single query or collection. They have no option to show the results from multiple queries/collections.

From this combination it follows that you can't show data from an OR condition with a single FirebaseUI adapter. You will have to create you own adapter for this, although you can certainly use the (open-source) FirebaseUI adapters for inspiration.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807