【发布时间】:2021-09-25 00:05:12
【问题描述】:
我正在尝试在我的应用程序中运行一个 Firestore 查询,该查询引发了一个索引缺失的错误。 Firestore 过去总是包含一个链接来单击控制台以创建丢失的索引,但这次它不存在所以我被卡住了! 不知道这次我做了什么不同的事情。
这是控制台错误:
prebuilt-d16b955d-cdb9e87f.js:188 Uncaught (in promise) FirebaseError: no matching index found.
at new e (prebuilt-d16b955d-cdb9e87f.js:188)
at prebuilt-d16b955d-cdb9e87f.js:10416
at prebuilt-d16b955d-cdb9e87f.js:10414
at e.onMessage (prebuilt-d16b955d-cdb9e87f.js:10403)
at prebuilt-d16b955d-cdb9e87f.js:10356
at prebuilt-d16b955d-cdb9e87f.js:10387
at prebuilt-d16b955d-cdb9e87f.js:15180
这是我的 JS 函数:
loadcatalogues() {
console.log(this.clubID);
this.showspinner = true;
this.catalogues = [];
var today = moment().utc().unix();
let self = this;
fb.catalogueCollection
.where("clubID", "==", this.clubID)
.where("expiry", ">", today)
.orderBy("expiry", "asc")
.orderBy("price", "asc")
.get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
if (
doc.data().members &&
doc.data().members.indexOf(self.userProfile.id) !== -1
) {
return false;
}
var starttime = moment.unix(doc.data().start).utc();
var endtime = moment.unix(doc.data().expiry).utc();
var tempdata = {
title: doc.data().title,
description: doc.data().description,
start: starttime.format("DD-MM-YYYY"),
expiry: endtime.format("DD-MM-YYYY"),
price: doc.data().price,
purchased: false,
stripeid: doc.data().stripeid,
catalogueid: doc.id,
limited: doc.data().limited,
};
self.catalogues.push(tempdata);
});
if (self.catalogues.length == 0) {
self.shownooptions = true;
}
self.showspinner = false;
});
},
如果我删除第一个 where 子句 (.where("clubID", "==", this.clubID)) 则查询运行良好,所以我猜测该查询已经存在索引。 我最近才添加了 clubID 字段,所以会不会缺少索引?
谢谢!!
【问题讨论】:
-
索引是long-running operation,这意味着它可能需要一段时间才能完成。该字段可能尚未编入索引。您可以尝试使用
gcloud firestore operations list查找正在进行的索引操作。另外,您是否在 Firestore 模式下使用 Datastore?如果是这样,这个线程可能会有所帮助:“no matching index found” Google Cloud Firestore Datastore library -
感谢 Farid - 我已经检查了 gcloud firestore 操作列表,没有任何明显的迹象可以显示长时间运行的索引操作。我使用的是 Firestore Native 而不是 Datastore 模式。直到最近才出现这种情况,这就是它如此奇怪的原因。
标签: firebase vue.js indexing google-cloud-firestore