I'm currently working on setting up a relationship between users and notifications in my app. Each user has many notifications and a single notification can have many users. I'm currently storing an array of user IDs on the notification document and an array of objects containing the notification ID along with a boolean flag indicating if it has been read or not on the user document. My requirements are as follows:
- I should be able to query all of a user's notifications. This can be done through pagination.
The notifications are both saved to the database and published to a unique channel for every user through Redis Pub/Sub. This is used in conjunction with GraphQL subscriptions allowing users to receive real time notifications in-app.
I need to be able to send a daily digest email blast to all users. Basically, this entails fetching all the users along with their unread notifications and parsing each individual user's notifications to generate an HTML email template and then update the boolean flag from unread to read.
My questions are:
What's the best way to handle querying all the users and their notifications? I'm assuming I should be processing the users in batches.
Is this an ideal way to arrange the schema? Eventually, I'm going to have to deal with the user documents growing too large because of the array size. How large can the array on the user document grow before I get close to the limit?