0

I am trying to fetch all questions which has "maths" tag, but instead of success it moves to failedListener.

db.collection("questionCollection")
                .orderBy("questionID", Query.Direction.DESCENDING)
                .whereArrayContains("tags","maths")
                .limit(3)
                .get()
                .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                    @Override
                    public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                        if (queryDocumentSnapshots.isEmpty()) {
                            Log.d(TAG, "onSuccess: LIST EMPTY");
                            return;
                        } else {
                            // Convert the whole Query Snapshot to a list
                            // of objects directly! No need to fetch each
                            // document.
                            questionList = queryDocumentSnapshots.toObjects(QuestionBO.class);

                            if (questionList != null && questionList.size() > 0)
                                mAdapter.updateQuestions(questionList);
                        }
                    }
                }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                e.printStackTrace();
                Toast.makeText(mContext,"Failed",Toast.LENGTH_LONG).show();
            }
        });

enter image description here

Exception

FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/project/testingproject-384af/database/firestore/indexes?create_index=EhJxd
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300

1 Answers1

0

Just click the link given to you in that error message. It will take you to the console and ask you to create the index that will satisfy the query you're trying to perform.

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