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
- HTTP Error 500 ''
Hello to everyone, I'm a Flutter developer and actually I'm developing an app using Appwrite.. during my tests and also massive ones I've noticed something we...
- Invalid type for attribute 'email': emai...
I'm using the node-appwrite SDK to create a table, the column payload looks like this: ```json [{"key":"email","type":"email","required":true, "size": 512}] ``...
- Auth not working
guys my appwrite auth isnt working? oauth works (Sign in with google n discord) i have 2 websites deployed where do i get help when i do sign in with email and ...