#Appwrite :: getLikesByUserIdAndPostId :: error AppwriteException: Invalid `documentId` param: UID m
16 messages · Page 1 of 1 (latest)
I want to check whether userId with postId is present in the collection or not. Thats why I am using Query.and()
So you want to get a list of documents that have a specific userId and postId?
It will only be a single entry, not multiple
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
after using listDocuments() its giving Argument of type 'string' is not assignable to parameter of type 'string[]'. forquery
Wrap your query variable in an array, like this
const likes = await db.listDocuments(palettegramDB, likesCollection, [query]);
ok
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
Please don't delete posts because the thread is still here and there's no context for others
Please also make sure to format your code using back ticks
sorry
now there is only one post and 1 user, userid is same but still i am getting same error. Header- https://cloud.appwrite.io/v1/databases/651d85ea69357206cfe5/collections/651d85ff826413d8f258/documents/664c96f400264fa88529 I am fetching userId from cookies.
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