javascript - Uncaught Error in snapshot listener: FirebaseError: no matching index found - Stack Overflow

I'm getting the above error when running the following query. I've not seen it before, can�

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 posite 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.

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 posite 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.

Share Improve this question edited Jul 16, 2021 at 2:57 Martin Zeitler 77.2k20 gold badges166 silver badges238 bronze badges asked Jul 14, 2021 at 7:43 Ray PurchaseRay Purchase 7623 gold badges19 silver badges47 bronze badges 6
  • I'm seeing the exact same thing today – nycynik Commented Jul 15, 2021 at 6:15
  • Hi, no, I'm still getting the error. Maximum number of posite indexes is 200, so it's not that either. Very frustrating – Ray Purchase Commented Jul 17, 2021 at 12:47
  • Ok, I've tried setting up a pletely new project and every query that would normally result in the console outputting a message (and link) to create an Index is now just outputting the above error. – Ray Purchase Commented Jul 17, 2021 at 14:19
  • 2 Getting the same error. Filed GitHub issue: github./firebase/firebase-tools/issues/3583 – Clive Townsend Commented Jul 17, 2021 at 23:10
  • 3 UPDATE: Just received this from Google: "...We have received several reports similar to yours and the engineering team is already working to solve it. I added your case to the developers affected by this issue to continue pushing the solution..." – Ray Purchase Commented Jul 18, 2021 at 14:49
 |  Show 1 more ment

4 Answers 4

Reset to default 3

This is an internal bug in the SDK.

Firebase team is working on it, follow the issue here.

That's a known issue with Client SDKs. 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. Just use the Firebase Functions Emulator locally with the Admin SDK.

Use an existing Firebase project or create a new one for this:

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.

The problem is you must create an index for your "where" and "orderBy" conditions in the indexes column in your cloud firestore.

Official documentation:

  1. Manage indexes in Cloud Firestore
  2. Indexes and pricing

you have to create a new index manually from firestore console

  1. Go to the Cloud Firestore section of the Firebase console.
  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./docs/firestore/query-data/indexing?authuser=0#create_a_missing_index_through_an_error_message

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744869712a4598185.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信