Many-to-Many relationship Schema Best Practice

Hello,
I’m designing a schema where events can have many tags and tags can belong yo many event. I would love yo be able to use MongoDb aggregator to determine trending event in the last 2 days based on numbers of events they had appeared. Im coming from an SQL background. What is the best design for this usecase and allow for scalability.
Also there will be a tag suggestion feature for users when creating their events

Event can have multiple tags
Tags can be used my multiple events.

Events will grow indefinitely and same for tags
I’m not sure uf referencing will be a good idea since they are both unbounded?

A Tag can have 30million post as the system grows. Im afraid it mught hit the 16mb document limit.

Anyone who can help please?

Can a single event really have infinite number of tags? How would they be displayed? In my experience the number of tags on an event would be somewhat limited (if nothing else, by the UI). In which case embedding tags as an array into events and aggregating via $unwind followed by $sortByCount (preferably with $limit after that) would be the way to get top tags…

Asya

1 Like

Thank you @Asya_Kamsky

Yes. Events can have limited number of tags (max of 10tags)

However, one of the feature is for users to get suggestion on tags while typing/creating their events based on tag that exist in the database

Would you have a suggestion as to how to go about that please.

I sincerely apprciate your response

Please, anyone who can help provide an answer to this?