基于数组项的获取集合给出“ FAILED_PRECONDITION:查询需要索引”

时间:2018-08-30 12:12:31

标签: java android firebase google-cloud-firestore

我正在尝试获取所有带有“数学”标签的问题,但不是成功,而是转移到了failedListener。

url.rsplit('/', 1)[-1]

enter image description here

例外

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();
            }
        });

1 个答案:

答案 0 :(得分:0)

只需单击该错误消息中给您的链接。它将带您进入控制台,并要求您创建满足您要执行的查询的索引。