Back

Following

  • 0
  • Users
  • Databases
  • Web
Bogdan Tvarina
19 Dec, 2023, 13:06

How can I create a following system like on social sites? When 1 user can follow for another. I need to create subcollection, but I do not know how is it possible. I need to array with users id that follow for another user.

TL;DR
The user is asking for help in creating a following system where one user can follow another. The suggested approach is to create a separate collection for followers, with the leader's ID and the follower's ID as fields. This is different from an array-based approach and can be implemented using Appwrite relationships or custom implementation. The user is confused about adding a followers array to a user document and adding attributes like user and follower. They are also unable to add the type as a user's ID. The solution is to select the appropriate type (e.g., String) and tick the "Array" option to add a followers array to the user's
ZachHandley
19 Dec, 2023, 13:34

Technically there are a lot of different ways you can do it, some use arrays, others use relationships, I personally would probably use a hybrid but here’s a guide that might help made pretty recently https://m.youtube.com/watch?v=8N-0Ef1oC1w

ZachHandley
19 Dec, 2023, 13:35

That’s flutterflow but the logic is the same, I had a better one one sec

Bogdan Tvarina
19 Dec, 2023, 14:38

but how can I add in appwrite that attribute into users collection? I didn't find any array or way to create subcollection with following users id

Bogdan Tvarina
19 Dec, 2023, 14:40

I've found only enum, but I can not to add the type as a user's id

Bogdan Tvarina
19 Dec, 2023, 14:43

also when I created the followers collection, I can not to add attributes like user and his follower, because follower is from users collection

Bogdan Tvarina
19 Dec, 2023, 14:47

I don't understand how to add a followers array with type of user's id into a user document

Ernest
19 Dec, 2023, 15:09

Appwrite supports arrays just select the type (e.g. for user id you'd select String) and in the form that appears tick Array . Unlike Firebase that provides a NoSQL DB, appwrite uses a SQL DB thus the idea of a subcollection is simply another collection that is related to a different collection either by appwrite relationships (that uses foreign keys) or custom implementation (doing it manually)

Ernest
19 Dec, 2023, 15:22

You're not supposed to add all the data about the user to the followers collection. Typically, it's enough just having the follower and the followed (for easy distinction let's use the term leader) ids. Example:

Following collection

leaderID | followerID user1 ID | user2ID (user1 follows user2) user3ID | user 8ID user2 ID | user1ID (user2 follows user1 back; mutual following)

NB: This is a relationship based approach which is different from the array based approach

Bogdan Tvarina
19 Dec, 2023, 16:35

Oh, that so simple 😅 .

Bogdan Tvarina
19 Dec, 2023, 16:35

ty

Neo
20 Dec, 2023, 08:00

Remember your indexes if you don’t want to have a very bad time as the data increases

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