#Appwrite :: getLikesByUserIdAndPostId :: error AppwriteException: Invalid `documentId` param: UID m

16 messages · Page 1 of 1 (latest)

zenith nexus
#

If you're using queries, you need to use listDocuments() instead. getDocument() can only be used if you are fetching a single document that you have the ID of already

sage ermine
#

I want to check whether userId with postId is present in the collection or not. Thats why I am using Query.and()

zenith nexus
#

So you want to get a list of documents that have a specific userId and postId?

sage ermine
#

It will only be a single entry, not multiple

zenith nexus
#

That shouldn't matter, it'll just return the one entry if there is only one. If you are doing anything with queries or you do not already know the ID of the document, you will need to use listDocuments() to fetch the data

sage ermine
#

after using listDocuments() its giving Argument of type 'string' is not assignable to parameter of type 'string[]'. forquery

zenith nexus
#

Wrap your query variable in an array, like this
const likes = await db.listDocuments(palettegramDB, likesCollection, [query]);

sage ermine
#

ok

sage ermine
#

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

    const userDoc = await db.getDocument(palettegramDB, usersCollection, userId);
    const postDoc = await db.getDocument(palettegramDB, postsCollection, postId);
    console.log("userId ",userDoc)
    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);
    
}

}
i am getting value in query=> userDoc and postDoc but there values are there in collection

slow thorn
sage ermine
sage ermine
#
    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