Problem
I’m trying to code a website that sells courses. It uses MongoDB. I have three collections of documents for each course: Course, Chapter, Lecture. Each course has n
chapters and each chapter has m
lectures. I also have users that can have a premium
status based on if they are paying for a subscription. Some courses are available for all users, while others are only available for premium
users. The content of each course is divided into its lectures, where each lecture has some sort of src (like the src to a json) that contains the link of the contents of the lecture. This content is sensitive data, and will be stored somewhere on an external storage provider like Amazon S3.
Question
My question is, how can I implement a database model, where it minimizes the risks of exposing this sensitive content to users that are unauthorized?
Current Ideas:
I have many different ideas, but I am not sure which one is the best, or if they are effective at all.
Idea 1
I store the src of the content in the lectures model, and only select it in my queries when a user is authorized. However, this has a high likelihood of accidentally revealing data if the .select()
is misused.
Idea 2
I create a separate collection called Content, and each Lecture references its own content document. Again, the content can be revealed by accident if the Content collection gets accidentally populated on the lecture document.
If anyone knows how I should go about this, it would be greatly appreciated.