Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Android firestore using "whereTo()" many times causes cost a lot?

I am making a function to classify by user’s region and MBTI.

Here is a code.

private void EventChangeListener() {
    //firestore.collection("Users").orderBy("time",Query.Direction.DESCENDING).limit(50)
    firestore.collection("Users").orderBy("time",Query.Direction.DESCENDING).limit(50)
            .whereEqualTo("gender","여자")
            .whereEqualTo("mbti","ENTP")
            .addSnapshotListener(new EventListener<QuerySnapshot>() {
                @Override
                public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
                    if(error != null){

                        if(progressDialog.isShowing()){
                            progressDialog.dismiss();
                        }

                        Log.e("Firestore error",error.getMessage());
                        return;

                    }

                    for (DocumentChange dc : value.getDocumentChanges()){

                        if (dc.getType() == DocumentChange.Type.ADDED){
                            userArrayList.add(dc.getDocument().toObject(User.class));
                        }

                        myAdapter.notifyDataSetChanged();
                        if(progressDialog.isShowing()){
                            progressDialog.dismiss();
                        }
                    }

                }
            });
}

Like this whereEqualTo().whereEqualTo().whereEqualTo() causes a lot cost??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If It is right, then is there any other way?

>Solution :

You are charged for number of documents that match your query and are returned. Number of query clauses do not affect cost. Using more filters like whereEqualTo().whereEqualTo().whereEqualTo() will ideally reduce number of matches and cost less.

For example, if you have a collection of 50 restaurants and you use 1 whereEqualTo on ‘city’ field then it’ll return and cost N only for restaurants that are present in that city. If you add another whereEqualTo on ‘ratings’ then number of matches might be even less than N.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading