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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...