gpt4 book ai didi

需要 Firebase 索引但未提供链接

转载 作者:行者123 更新时间:2023-12-05 02:40:53 28 4
gpt4 key购买 nike

Tip: instead of creating indexes here, run queries in your code – if you're missing any indexes, you'll see errors with links to create them.Learn more

我收到一个错误找不到匹配的索引,没有通常的直接链接来创建所需的索引。

enter image description here

我的数据库结构如下:

answers (collection)
- $docId (document)
- $refId (collection)
- $docId (document)
- created_at (timestamp)
- type (string)

我的查询是:

firebase.firestore()

.collection('answers')
.doc('abcdHajM930Gabcd')
.collection('abcdetIo25xYqAabcd')
.orderBy("created_at", "desc")
.limit(5)
.where("type", "==", "3")

我已经尝试了所有我能想到的索引组合(下面的屏幕截图),我做错了什么?

<表类="s-表"><头>集合字段类型<正文>答案创建于:DESC类型:数组答案创建于:DESC类型:数组答案创建于:DESC类型:ASC答案创建于:DESC类型:ASC答案类型:ASC创建于:DESC答案类型:ASC创建于:DESC

enter image description here

最佳答案

更新:issue似乎已修复,Javascript 客户端 SDK 现在返回索引创建链接。


我不完全确定这是否是 Firebase JS SDK 的意图,但如果您尝试在 Cloud Functions 中运行查询(只需使用模拟器),那么它应该会抛出一个错误,其中包含创建索引的链接.

export const getIndexLink = functions.https.onRequest(async (request, response) => {
// functions.logger.info("Hello logs!", {structuredData: true});
try {
const snap = await admin.firestore().collection('answers')
.doc('abcdHajM930Gabcd')
.collection('abcdetIo25xYqAabcd')
.where("type", "==", "3")
.orderBy("created_at", "desc")
.limit(5).get()
console.log(snap.size)
response.send("Hello from Firebase!" + snap.size);
} catch (error) {
console.log(error)
response.send(error.message)
}
});

我尝试复制您的查询并使用 URL 创建了一个索引,结果索引是:

enter image description here

您正在使用的字段不是“答案”集合文档的一部分。现在,如果您更改子集合名称,它将需要另一个索引。您的 Firestore 结构是什么样的?我建议稍微重组它并获得相同的子集合名称并创建一个具有 collectionGroup 范围的索引。

关于需要 Firebase 索引但未提供链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68388195/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com