Back

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

  • 0
  • Web
Arti Gaund | Contributor
20 May, 2024, 13:34

const getLikesByUserIdAndPostId = async( userId: string, postId: string) => { try { console.log("userId ",userId,"postId ",postId); const query = Query.and([ Query.equal("userId", userId), Query.equal("postId",postId) ]) const likes = await db.getDocument( palettegramDB, likesCollection, query ) return !!likes; } catch (error) { console.log("Appwrite :: getLikesByUserIdAndPostId :: error ",error);

TypeScript
}

}

TL;DR
Appwrite developer had an error with `getLikesByUserIdAndPostId` function due to `Invalid documentId` param. They should wrap the `query` variable in an array and use `listDocuments()` instead of `getDocument()`. This function will check if a userId with postId is present in the collection.
Ryan
20 May, 2024, 13:38

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

Arti Gaund | Contributor
20 May, 2024, 13:41

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

Ryan
20 May, 2024, 13:42

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

Arti Gaund | Contributor
20 May, 2024, 13:43

It will only be a single entry, not multiple

Ryan
20 May, 2024, 13:44

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

Arti Gaund | Contributor
20 May, 2024, 13:45

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

Ryan
20 May, 2024, 13:46

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

Arti Gaund | Contributor
20 May, 2024, 13:47

ok

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