I'm trying to filter documents in my database based on whether a user's email is in the shared_with array field.
Here's the error I am getting: Uncaught TypeError: file2.role.includes is not a function
And here's my code:
TypeScript
export const fetchMetadata = async (userId: string) => {
try {
// query database for files owned by the user
const ownedFilesMetadata = await database.listDocuments(import.meta.env.VITE_DATABASE_ID, import.meta.env.VITE_FILE_METADATA_COLLECTION_ID, [Query.equal("ownerId", userId)]);
// query database for files shared with the user
const sharedFilesMetadata = await database.listDocuments(import.meta.env.VITE_DATABASE_ID, import.meta.env.VITE_FILE_METADATA_COLLECTION_ID, [Query.search("shared_with", userId)]);
return {
ownedFilesMetadata: ownedFilesMetadata.documents,
sharedFilesMetadata: sharedFilesMetadata.documents
}
} catch (error) {
console.log(error);
return {
ownFilesMetadata: [],
sharedFilesMetadata: [],
}
}
}
What do you think I'm doing wrong?
TL;DR
Issue: Getting a `Uncaught TypeError: file2.role.includes is not a function` error when filtering documents based on whether a user's email is in a specific array field.
Solution: The error might be due to trying to use the `includes()` method on a non-array field. Make sure `file2.role` is an array before calling `includes()` on it.Recommended threads
- Appwrite DNS nameservers return SERVFAIL...
My custom domain demomanasa.online (and all its subdomains) stopped resolving with ERR_NAME_NOT_RESOLVED for all visitors. I have traced the failure to Appwrite...
- Framework categorization for Sites
Hello, I want to deploy my web app via Appwrite SItes. My web app is vite+reactjs. In the Appwrite docs, it creates a vite+react app, and chooses React from the...
- Attribute not found in schema on REST AP...
I'm querying a appwrite collection via the REST API on appwrite cloud 1.9.5 (no SDK) via a cloudflare worker and keep getting: ``` {"message":"Invalid query: A...