There have been many similar questions but they are all about followers/followees where each other is following the other (bot sides could potentially grow very large)
my case: I have users, each user can follow products. Each user has a watchlist (summary of all watched items). I want to be able to send notification to all users who follow a spec. product when something about the product has changed. So I need to query all followers of a specific product (there will be many products but they will never grow as big as the document size limit would be reached)
first approach
pro: only one lookup to get followerIds (lookup of collection followed)
con: 16mb per document limit would be potentially reached because followeeIds in followed could grow very big
1. collection users:
- userid
- username
- userpassword
- other info user
2. collection following:
- userid
- [array of followingIds] //productIds
3. collection followed (watchlist):
- productId
- [array of followeeIds]
second approach
pro: 16mb per document limit would not be reached
con: would be 2 queries as I understand -have to search through all users + followeeIds to see who is follower
1. collection users:
- userid - username
- userpassword
- other info user
- followeeIds: [] //ids of products user follows
2. collection followed (watchlist)
- userId
- reference to product or embedded product
3rd approach:
I would reference users in my followee collection. Im not sure if this would lead to less queries/better performance
1. collection users:
- userid - username
- userpassword
- other user specific info user
2. collection following:
- userid
- [array of followingIds] //productIds (no reference as it would never grow as large as userIds)
3. collection followed:
- productId
- followee: {
type: Schema.Types.ObjectId,
ref: 'user'
} //here instead of having array of userIds, I reference user
4th approach: here I would not use arrays so lets say user 1 follows 5 products, there will be 5 documents belonging to collection Follow.
1. collection users:
- userid - username
- userpassword
- other info user
2. collection follow
- userid (the follower)
-productId (followee)
3. collection Watchlist (this is to show users watchlist, not for sending notifications to all followers of product xyz
- userId
-embedded or reference to product