Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 Console Error

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.

like image 705
Ray Purchase Avatar asked Jul 14 '21 07:07

Ray Purchase


2 Answers

This is an internal bug in the SDK.

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

like image 93
Corentin Houdayer Avatar answered Oct 29 '22 00:10

Corentin Houdayer


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.

like image 37
Dharmaraj Avatar answered Oct 29 '22 00:10

Dharmaraj