简体   繁体   English

快照侦听器中未捕获的错误:FirebaseError:找不到匹配的索引

[英]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:这是一个“新”查询,因为我刚刚将它添加到代码中,所以我可能期望控制台中的错误提供了一个链接,用于创建一个新的复合索引或任何它被调用的名称,但我只是得到这个:

Firestore 控制台错误

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.我也在同一页面上得到了一个查询,除了集合名称之外,它完全相同,并且工作正常。

This is an internal bug in the SDK.这是 SDK 中的内部错误。

Firebase team is working on it, follow the issue here . Firebase 团队正在研究它,请在此处关注问题。

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:官方文档:

  1. Manage indexes in Cloud Firestore 管理 Cloud Firestore 中的索引
  2. Indexes and pricing 指数和定价

you have to create a new index manually from firestore console您必须从 Firestore 控制台手动创建一个新索引

  1. Go to the Cloud Firestore section of the Firebase console.转到 Firebase 控制台的 Cloud Firestore 部分。
  2. Go to the Indexes tab and click Add index.转至索引选项卡,然后单击添加索引。
  3. Enter the name of the collection and set the fields you want to use to sort the index.输入集合的名称并设置要用于对索引进行排序的字段。
  4. Click Create.单击创建。

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.

相关问题 快照侦听器中未捕获的错误:FirebaseError:缺少权限或权限不足 - Uncaught Error in snapshot listener: FirebaseError: Missing or insufficient permissions 快照侦听器中的未捕获错误:,FirebaseError:[code = permission-denied]:缺少或权限不足 - Uncaught Error in snapshot listener:, FirebaseError: [code=permission-denied]: Missing or insufficient permissions “获取文档时出错:FirebaseError:找不到匹配的索引。” — 尝试在两个字段上使用 WHERE 子句 - “Error getting documents: FirebaseError: no matching index found.” — trying to use WHERE clause on two fields 快照侦听器中未捕获的错误。 超出 Firebase 配额 - Uncaught Error in snapshot listener. Firebase quota exceeded 如何修复 onSnapshot 中的未捕获错误:FirebaseError:查询需要索引。 关于动态排序? - How to fix Uncaught Error in onSnapshot: FirebaseError: The query requires an index. on dynamic sorting? Firebase onSnapshot 中未捕获的错误:[FirebaseError:缺少权限或权限不足。] - Firebase Uncaught Error in onSnapshot: [FirebaseError: Missing or insufficient permissions.] index.esm2017.js:370 未捕获(承诺)FirebaseError:ReactJs 中权限缺失或不足 - index.esm2017.js:370 Uncaught (in promise) FirebaseError: Missing or insufficient permissions in ReactJs 未捕获(承诺)FirebaseError:没有要更新的文档 - Uncaught (in promise) FirebaseError: No document to update Firestore 快照侦听器:“null 不是对象”错误 - Firestore snapshot listener: 'null is not an object' error Firebasse 中的错误“assert.ts:128 Uncaught FirebaseError: Firebase: Error (auth/invalid-api-key) - Error in Firebasse"assert.ts:128 Uncaught FirebaseError: Firebase: Error (auth/invalid-api-key)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM