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
- Password check in function
Hi, is there any way now for checking if the users password is correct in a function? I am creating a delete user function and before deleting I would like to c...
- DB connection | Got timeout reading comm...
When looking at the logs of `appwrite-mariadb` I'm seeing a lot of: ``` 2026-04-09 7:37:28 10 [Warning] Aborted connection 10 to db: 'appwrite' user: 'appwrit...
- Invalid document structure: Unknown attr...
Environment: Dart version: 3.5.1 dart_appwrite: 13.0.0 I’ve already created the database structure using a Dart function. I can create data records using cloud...