0

I am trying to retrieve data from a firestore collection according to the filters user is choosing. He also has the option for no filter. I am trying to use the filters in calling data from firestore using "where".I am using the Firestore query documents startsWith a string. But this works for only one filter as android does not lalow multiple of this and I need 4. How to do this? Here is my code for calling

 CollectionReference collectionReference = db.collection("Tasks");
        collectionReference
                .whereGreaterthanorEqualTo("City",""+City)//I want to add multiple of these filters
                
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()) {
                            for (QueryDocumentSnapshot document : task.getResult()) {
                                String s = document.getId();
                                list.add(s);
                            }

                                mAdapter = new MyAdapter(list, TaskList.this);
                                recyclerView.setAdapter(mAdapter);
                                mAdapter.notifyDataSetChanged();

                        }

                    }
                });

Any help will be appreciated

  • @DougStevenson that works only for 1 in android studio. That does not answer my question –  Jul 08 '20 at 03:42
  • It's not possible. Firestore does not support using multiple range filters on different fields. Read the documentation: https://firebase.google.com/docs/firestore/query-data/queries#compound_queries – Doug Stevenson Jul 08 '20 at 04:03
  • For 4 can I use GreatherThanOrEqualTo,GreaterThan,SmallerTha,SmallerThanOrEqualTo or will this not work –  Jul 08 '20 at 04:04
  • Just try it, then see what the error message says. – Doug Stevenson Jul 08 '20 at 04:35
  • I cannot try right now as I have my school. Will inform you as soon as I try it. I may have to request for the rest of documents and then apply a starswith filter in android studio itself –  Jul 08 '20 at 04:48
  • Sorry for being late. But I tried it and I have some answers. 1> Firebase can takes multiple greaterThanOrequal to filters and all those others, but these all need to be on the same field. 2> You can simply apply the startswith filter in java itself. –  Jul 09 '20 at 04:42

0 Answers0