async removeUserLike(userId, postId) { try { console.log(userId, postId); const searchLikedUser = await this.getAllByQueries( [Query.equal("post_id", postId), Query.equal("user_id", userId)], config.appwriteLikeId );
if(searchLikedUser.documents.length > 0){
const user = searchLikedUser.documents[0].$id;
return await this.databases.deleteDocument(
config.appwriteDatabaseId,
config.appwriteLikeId,
user
);
}
console.log("liked id removed successfully");
} catch (error) {
console.log("Error while removing like:", error.message);
}
}
some adjustment
async removeUserLike(userId, postId) {
try {
console.log(userId, postId);
const searchLikedUser = await this.getAllByQueries(
[
Query.equal("post_id", postId),
Query.equal("user_id", userId)
],
config.appwriteLikeId
);
if (searchLikedUser.documents.length > 0) {
const user = searchLikedUser.documents[0].$id;
await this.databases.deleteDocument(
config.appwriteDatabaseId,
config.appwriteLikeId,
user
);
console.log("liked id removed successfully");
return true; // To confirm the action was successful.
} else {
console.log("No like found for the user and post.");
return false; // Indicates that no like existed.
}
} catch (error) {
console.log("Error while removing like:", error.message);
}
}
I had a look at the code, and it seems like the flow should work, but I'm wondering what specific issue you're encountering¿
When i want to remove the likes from appwrite, it doesn't remove at all
As far as I know, appwrite doesn't support updating array attributes directly.
typically, you would need to fetch the current likes, perform the necessary operations (like removing the desired like), and then push the updated data back to the document
Recommended threads
- Subject: Seeking Advice on Adding AI to ...
hope you’re all doing well! My name is Ashish Nagvanshi, and I’m currently working on building my first SaaS product aimed at transforming the way people choose...
- Issue calling functions from vercel
I have created a express API function. I was facing issue calling the function directly via its apprwrite URL on local env so I tried adding a proxy this worked...
- Could not find user session: app.<projec...
Hello, **Error** : Could not find user session: [email protected] (role: applications) missing scope (account) I have this ...