Chidera Humphrey
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
- Hello I used appwrite to display data on...
How can I solve that?
- Can't create User and send Verification
Hey 😄 I'm not able to create a User und send him a verification mail. Always receive `/v1/account/verification 401 (Unauthorized)` there is no old session, ...
- how React Native Query with API key
how to perform acton to collectons which React Native SDK user having no permission. actually, I can give them permissons but considering it would be redudancy...