【发布时间】:2018-08-30 12:12:31
【问题描述】:
我正在尝试获取所有带有“maths”标签的问题,但它没有成功,而是转移到 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
【问题讨论】:
-
那么打印的异常是什么?
-
你得到什么异常?
-
我们需要更多关于这个问题的信息。你得到什么样的例外?
-
我已经更新了异常。该查询需要索引
-
所以我猜异常已经回答了你的问题,不是吗?
标签: java android firebase google-cloud-firestore