Hi Igor,
A Letter can be sent in a context of Topic that is shared between group of users.
So, the Topic model has the following structure:
- _id
- name (String)
- users_ids (Array of users ids, that can send letters withing this topic)
Also, each user can remove a letter for himself.
Both of your concerns for the two variants you posted was correct. The $nin
query in variant 1 cannot use an index, hence performance will likely suffer. Additionally in variant 2:
- _id (ObjectId)
- text (String)
- topic_id (ObjectId)
- accesible_for_users_ids (Array)
If a letter is accessible to all users by default, you would have to insert the whole user array into the accesible_for_users_ids
field every time a new letter is inserted. If your user array is large, these inserts will be expensive. This may not be ideal for performance reasons.
If applicable to your use case, you may find the Socialite project useful as a guide. Socialite explores the design, scaling, and challenges of creating a social network status feed in a series of presentations in MongoDB World 2014. The presentation series consists of:
Best regards,
Kevin