Back

Appwrite :: getLikesByUserIdAndPostId :: error AppwriteException: Document with the requested ID co

  • 0
  • Web
Arti Gaund | Contributor
20 May, 2024, 19:35

const getLikesByUserIdAndPostId = async( userId: string, postId: string) => { try { console.log("userId ",userId) console.log("postId ",postId) console.log("likesCollection ",likesCollection)

TypeScript
    const userDoc = await db.getDocument(palettegramDB, usersCollection, userId);
    const postDoc = await db.getDocument(palettegramDB, postsCollection, postId);
    if (userDoc && typeof userDoc === 'object') {
        console.log("userId ", userDoc);
      } else {
        console.log("Error fetching user document");
      }
    console.log("postId ",postDoc)
    const query = Query.and([
        Query.equal("userId", userDoc.$id),
        Query.equal("postId",postDoc.$id)
    ])
    const likes = await db.listDocuments(
        palettegramDB,
        likesCollection,
        [query]
    ) 
    return !!likes;
} catch (error) {
    console.log("Appwrite :: getLikesByUserIdAndPostId :: error ",error);
    
}

} but there is data in usersCollections and postsCollection but it throwing error bz userDoc and postDoc value is null

TL;DR
Developers are encountering an error while trying to get likes by user ID and post ID using Appwrite, specifically with user and post document values being null. They have checked permissions and granted 'Any' access, but the issue persists. Screenshots were requested but not shared, and the error seems to occur during the retrieval of user and post documents. Further troubleshooting is needed to resolve this issue.
Steven
20 May, 2024, 19:38
Arti Gaund | Contributor
20 May, 2024, 19:39

it was not same error

Steven
20 May, 2024, 19:45

What are the permissions on the collections and is document level security enabled?

Arti Gaund | Contributor
20 May, 2024, 19:46

all modification, read, create,update,delete

Arti Gaund | Contributor
20 May, 2024, 19:49

There is usersCollection with user details, postsCollection with post details and likesCollection have user reference with post reference. I am trying to fetch whether user is present in likesColllection with post id. This futher does that only ```const getLikesByUserIdAndPostId = async( userId: string, postId: string) => { try { console.log("userId ",userId) console.log("postId ",postId) console.log("likesCollection ",likesCollection)

TypeScript
    const userDoc = await db.getDocument(palettegramDB, usersCollection, userId);
    const postDoc = await db.getDocument(palettegramDB, postsCollection, postId);
    if (userDoc && typeof userDoc === 'object') {
        console.log("userId ", userDoc);
      } else {
        console.log("Error fetching user document");
      }
    console.log("postId ",postDoc)
    const query = Query.and([
        Query.equal("userId", userDoc.$id),
        Query.equal("postId",postDoc.$id)
    ])
    const likes = await db.listDocuments(
        palettegramDB,
        likesCollection,
        [query]
    ) 
    return !!likes;
} catch (error) {
    console.log("Appwrite :: getLikesByUserIdAndPostId :: error ",error);
    
}

}``` but its showing error. When I tried to console the value its throwing error on userDoc and postDoc.

Steven
20 May, 2024, 19:51

Please share a screenshot

Arti Gaund | Contributor
20 May, 2024, 19:52
Steven
20 May, 2024, 19:53

Please try granting Any access

Arti Gaund | Contributor
20 May, 2024, 19:56

its throwing same error for any access as well.

Steven
20 May, 2024, 19:57

What about the related collections?

Arti Gaund | Contributor
20 May, 2024, 19:57

I have given any access to all collections likesCollection, postsCollection and userCollections

Steven
20 May, 2024, 19:58

Screenshots please

Arti Gaund | Contributor
20 May, 2024, 19:58

of any access?

Steven
20 May, 2024, 19:58

Yes

Arti Gaund | Contributor
20 May, 2024, 19:59
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more