[Solved] Server Error for queries even though I created an index for all attributes
- 0
- Resolved
- Databases
- Web
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
what's yoru error?
Do I need to change the queryArray for each of these scenarios so that only defined search variables are used in the query array?
Yes. I would have an array of queries and then add a Query.equal() or whateveer for whatever the user selects
Oh, ok, thanks. I wasn't sure if it was another error or if it was my theory that every search variable needs to be defined before it is used for the queries. Beforehand, I'd assumed that undefined queries would be ignored and only the defined ones would be used to list the documents
Also, thanks for the tip about appending the queries to the query array depending on if the variables are defined or not
[Solved] Server Error for queries even though I created an index for all attributes
Recommended threads
- MariaDB refuses to connect to appwrite
Earlier, I tried updating my Appwrite version from 18.1.x to the latest release because my Flutter package required it to function properly. I used the official...
- Custom API domain is unreachable
Earlier my custom api domain was working fine. Now it seems to be offline without a trace a few hours later. I didn't change anything, all the relevant DNS reco...
- "Invalid console fingerprint" when unpau...
I've tried logging out and logging back in, still can't figure out why this is happening.