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
- Worker functions stuck on "Fetched 0 fun...
Appwrite Version: 1.9.0 Bug Description: The appwrite-worker-functions container gets stuck in an infinite loop logging "Fetched 0 functions..." while scheduled...
- Upgrading selfhost version?
It is okay to upgrade version to higher one, of my current version is 1.7.4 to 1.8.1. Is that safe to do cause my clients already have data on that? Also is a...
- I am using s3 for app storage but is it ...
_APP_STORAGE_DEVICE=s3 puts everything to the s3 storage but i need to be able to keep the function builds and site in the local and not waste the cloud storage...