0

Im using FirestorePagingAdapter in the FireStoreUI framework to create a simple query and get results into a recycler view.

I am able to fetch results and display them if I use a simple query:

var mQuery = FirebaseFirestore.getInstance().collection("test")

But in my application I have a searchView which I will be using to add queries options in mQuery eg:

var mQuery : Query = FirebaseFirestore.getInstance().collection("test")
        if (!searchString.isNullOrEmpty()) {
            println("SearchView: $searchString")
            mQuery.whereGreaterThanOrEqualTo("name", searchString)
        }

But this does not work. Can we not add options to Query after it has been assigned?

uniQ
  • 115
  • 2
  • 16

1 Answers1

2

Query objects are immutable. They can't be changed after created. Notice from the API documentation that whereGreaterThanOrEqualTo() returns a new Query object (as well as all filters) with the new condition added to it. So, you can just reassign mQuery with the new Query it built.

See also: Conditional where clause in firestore queries

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441