Rank 2: Process
I am getting an Appwrite server error for my query even though I created an index that encompasses all the relevant attributes.
Here is the code:
Query.orderDesc("$createdAt"), Query.equal("subject", [subject]), Query.equal("education_level", [educationLevel]), Query.search("question", [searchTerm])]
const refresh = async () => { try { console.log(collectionId) const response = await databases.listDocuments(databaseId, collectionId, queryArray) console.log(response); setNotes(response.documents); setLoading(false); } catch (error) { console.error(error); }};```
When I remove all the queries except for Query.orderDesc, it works fine. The subject, educationLevel and searchTerm are variables that are set by the parent component and passed down as props so they aren't always defined. The queries are meant to work like filters where if the user wants to filter by question, subject, educationLevel or all 3 they can. Do I need to change the queryArray for each of these scenarios so that only defined search variables are used in the query array? For example if the user only fills in the searchTerm variable, queryArray needs to be [ Query.orderDesc("$createdAt"), Query.search("question", [searchTerm])]
I tried the array above and it also worked after I added a question only index. Therefore, I'm not sure if I have to change queryArray for each scenario or not but it seems like I do. However, if I can avoid that and keep the code simple, that would be great