
I have a collection Called Relationship and i am fetching a doc from collection using its id
i have valid id but its not fetching doc and return undefined
TypeScript
export async function getRelationship(relationshipId: string) {
try {
const relationship = await databases.getDocument(
config.databaseId,
config.relationshipCollectionId,
relationshipId
);
if (relationship.documents.length === 0 || !relationship.documents) {
console.error("No Relationship Found");
return null;
}
return relationship.documents[0];
} catch (error) {
console.error("Error getting relationship:", error);
return null;
}
}```
TL;DR
Issue: Developer is unable to fetch document from the 'Relationship' collection using its ID. The function is returning 'undefined' even with a valid ID.
Solution: Check if the condition for checking relationship documents is correct. Update the condition to check if 'relationship.documents' is truthy before accessing its length property. This will ensure that the function does not throw an error and returns the document as expected.Recommended threads
- Need help in email verification - react ...
Hi, i am trying to verify user, but it is asking me a redirect link, and as i am creating an mobile app, i want it to be done in the app itself. Please if anybo...
- Bug: When creating a table, table name i...
I created a table with a typo. my_taable .... then my code couldn't find it. i updated table name and still couldn't find it. the table name doesn't update. i h...
- Display an in-app in the user mobile?
Would it be possible to send a message that would display an in-app in the user mobile?
