#AppwriteException: Document with the requested ID co

42 messages · Page 1 of 1 (latest)

patent jewel
#

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

    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

sinful fulcrum
patent jewel
#

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)

    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.

sinful fulcrum
patent jewel
sinful fulcrum
patent jewel
#

its throwing same error for any access as well.

sinful fulcrum
patent jewel
#

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

patent jewel
sinful fulcrum
patent jewel
sinful fulcrum
patent jewel
#

yes

sinful fulcrum
patent jewel
sinful fulcrum
# patent jewel

Would you please share a screenshot of the user document that you're trying to get?

#

And the url of that page

sinful fulcrum
patent jewel
sinful fulcrum
sinful fulcrum
sinful fulcrum
#

you passed the wrong document id

patent jewel
#

headers Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-Appwrite-JWT, X-Appwrite-Response-Format, X-Appwrite-Timeout, X-Appwrite-Shared-Tables, X-SDK-Version, X-SDK-Name, X-SDK-Language, X-SDK-Platform, X-SDK-GraphQL, X-Appwrite-ID, X-Appwrite-Timestamp, Content-Range, Range, Cache-Control, Expires, Pragma, X-Forwarded-For, X-Forwarded-User-Agent

#

ok I got it.

sinful fulcrum
#

[SOLVED] AppwriteException: Document with the requested ID co

patent jewel
#

This thread was not visible.

heavy mauve
sinful fulcrum
patent jewel
sinful fulcrum
#

AppwriteException: Document with the requested ID co

patent jewel
#
    try {
        console.log("userId ",userId)
        console.log("postId ",postId)
        console.log("likesCollection ",likesCollection)
        
        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);
        
    }
}```will this method will not return true if data found, and false if data not fount?
userDoc and postDoc still not fetching data, as their console is not showing any output
sinful fulcrum
patent jewel
#

const userDoc = await db.getDocument(palettegramDB, usersCollection, userId); its throwing error here, bz below console outputs are not coming.