[英]Uncaught Error in snapshot listener: FirebaseError: no matching index found
I'm getting the above error when running the following query.运行以下查询时出现上述错误。 I've not seen it before, can't find any documentation about it, and I'm not doing anything unusual or anything I've not done before.我以前没有见过它,找不到任何关于它的文档,而且我没有做任何不寻常的事情或我以前没有做过的任何事情。 Can anyone shed any light on it, please?任何人都可以对此有所了解吗?
const getUserProjects = async () => {
return await useFireStore
.collection('projects')
.where('paid','==',true)
.where('ownerId','==', `${currentUser.uid}`)
.orderBy('createdAt', 'desc')
.onSnapshot(snapshot => {
let projects = [];
snapshot.forEach(doc => {
projects.push({...doc.data(), id: doc.id })
});
setUserProjects(projects);
});
};
It is a 'new' query in that I've just added it to the code, so I might expect the error in the console that gives a link for a new composite index to be created or whatever it's called, but I'm just getting this instead:这是一个“新”查询,因为我刚刚将它添加到代码中,所以我可能期望控制台中的错误提供了一个链接,用于创建一个新的复合索引或任何它被调用的名称,但我只是得到这个:
EDIT: I have tried manually creating an Index, but I still get the same error.编辑:我尝试手动创建索引,但仍然遇到相同的错误。 I have also got a query on the same page which is exactly the same apart from the collection name, and that works fine.我也在同一页面上得到了一个查询,除了集合名称之外,它完全相同,并且工作正常。
That's a known issue with Client SDKs .这是客户端 SDK的一个已知问题。 However the Admin SDK still works as usual and returns throws an error containing the link to create index and can be used a workaround.但是,Admin SDK 仍然照常工作,并返回一个包含创建索引链接的错误,可以用作解决方法。 Just use the Firebase Functions Emulator locally with the Admin SDK.只需通过 Admin SDK 在本地使用 Firebase Functions Emulator。
Use an existing Firebase project or create a new one for this:使用现有的 Firebase 项目或为此创建一个新项目:
firebase init functions
Copy the following function:复制以下函数:
export const getIndexLink = functions.https.onRequest(async (request, response) => {
try {
const snap = await admin.firestore()...get()
// Paste your query here
response.send(snap.size, "matched documents");
} catch (error) {
console.log(error)
response.send(error.message)
// This error will contain the index creation link
}
});
Run the function emulator:运行函数模拟器:
firebase emulators:start --only functions
Open a browser and paste your getIndexLink
function's URL and you should have the URL to create index there.打开浏览器并粘贴您的getIndexLink
函数的 URL,您应该拥有在那里创建索引的 URL。
The problem is you must create an index for your "where" and "orderBy" conditions in the indexes column in your cloud firestore.问题是您必须在云 Firestore 的索引列中为“where”和“orderBy”条件创建索引。
Official documentation:官方文档:
you have to create a new index manually from firestore console您必须从 Firestore 控制台手动创建一个新索引
more information: https://firebase.google.com/docs/firestore/query-data/indexing?authuser=0#create_a_missing_index_through_an_error_message更多信息: https : //firebase.google.com/docs/firestore/query-data/indexing?authuser=0#create_a_missing_index_through_an_error_message
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.