java - 基于数组项获取集合给出“FAILED_PRECONDITION:查询需要索引”
问题描述
我正在尝试获取所有带有“数学”标签的问题,但它没有成功,而是转移到 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
解决方案
只需单击该错误消息中提供给您的链接。它会将您带到控制台并要求您创建满足您尝试执行的查询的索引。
推荐阅读
- javascript - 如果在 Javascript 中指定小数时间,如何计算最接近的整数时间单位
- javascript - 如何从外部函数解决 JS 承诺?
- oracle - SQLLDR format single digit month and date
- mapbox - Mapbox - sourced vector file unable to add fill color
- unit-testing - 编译器错误的单元测试打字稿
- sql - "Down" Casting columns while doing a UNION ALL (MS Sql Server 2012)
- mysql - Find unmatched records from columns (Union) Sql
- php - 用 php 更新 mysqli 数据库
- google-cloud-kms - Google Cloud KMS:离线解密
- java - 导出用 cplex 求解的数学模型