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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With