基于数组项的取回收集给出& quot; FAILED_PRECONDITION:查询需要索引& quot; [英] Fetch collection on basis of array item gives "FAILED_PRECONDITION: The query requires an index"

查看:26
本文介绍了基于数组项的取回收集给出& quot; FAILED_PRECONDITION:查询需要索引& quot;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取所有带有数学"标记的问题,但它没有成功,而是转移到了failedListener.

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

例外

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

推荐答案

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

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.

这篇关于基于数组项的取回收集给出&amp; quot; FAILED_PRECONDITION:查询需要索引&amp; quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆