Skip to content
Back

How to Count “likes” (like on instagram) ?

  • 1
  • Databases
  • Flutter
  • Functions
  • Cloud
electrical_eng_l
5 Dec, 2024, 17:34

How do I approach showing likes count on a post ?

I have created a database which has the userID of the users who liked .

How do i show the number ?

I also wanna have a special “Top Liked” tag if the post has over 1,000 likes .

Is this done via functions or is there a way to do it via Databases ?

TL;DR
To show the likes count on a post, you can query your `likes` collection for userIDs and count how many are linked to that post. To add a "Top Liked" tag for posts with over 1,000 likes, check if the like count is over 1,000 and set the tag accordingly. You can automate this process using an Appwrite function, but it can also be done with database queries and logic in your app.
Nishant
5 Dec, 2024, 17:41

hey @Thatguyx! I believe to show the likes count, you can just query your likes collection where you store the userIDs. Then, count how many userIDs are linked to that post. Like this:

TypeScript
const likedPost = await database.listDocuments('likesCollection', [
    Query.equal('postId', postId)
]);
const likeCount = likedPost.documents.length;

and for the "Top Liked" tag, you can just check if the likeCount is over 1,000, and if it is, you can set that tag:

TypeScript
let tag = '';
if (likeCount > 1000) {
    tag = 'Top Liked';
}

umm, also, if you want to automate this (like updating the tag when it hits 1,000 likes), you could use an Appwrite function, but honestly, the database and a little logic in your app should do the trick. ^^

lmk if it works or if you need further help : )

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more