I’m working on a social media app. Is there a way i configure a user to have only a certain number of friends.
Yes. Create a “Friends Count” property in the users collection.
Each time they add a friend, update the count + 1. Each time they remove a friend, update the count - 1.
Then you set a condition to the action of adding a friend. If “Friends Count” is greater than X then block or show them an alert.
Above is an idea on how to approach this.
Hey there @charleshope & @Sachin
You can do this without the number parameter in the users collection as you can access and validate the counts directly in the conditions of actions.
For example, let’s say I want to set a cap of 10 “Friends”. In this example, “family members” is the “friends” relationship parameter. This is the friend request action with a condition that validates that the user’s friends count is less than 10.
That’s true.
However, performing those calculations consumes more time than comparing values. That’s why I suggested the property.
But both ways will work.
The way that I mentioned will be faster in general as it only gets and validates the count once whereas your method gets, updates, gets, then validates.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.