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
- trying to figure out how to activate my...
please help
- Bug: TOTP MFA verification always fails ...
*Bug: TOTP MFA verify always returns `user_invalid_token` (Cloud 1.8.1, Frankfurt)** Project ID: `68dd48440003e537d849` SDK: `appwrite@18.2.0` (also tested wit...
- SSL Certificate Issuance Failed
When we first deployed our site using appwrite and a custom domain everything was working, but it seems like the SSL certificate never got renewed. I tried dele...