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
- Problem with Google Workspace at DNS Rec...
Hello, I bought a domain at Namecheap, and Google Workspace used to work there, but now that I switched from Custom DNS to Appwrite's nameservers, it doesn't w...
- change role of a team member in Appwrite
It's not possible to add/change roles of a team meber in Appwrite Frontend. When you click on a member of a team you get forwarded to the configuration page of ...
- Session not found. Please run appwrite l...
I have encounter an issue with appwrite CLI They asking for a login session but in the doc, it’s mention that only setup client with endpoint / api key is enou...