New MongoDB user here with SQL knowledge.
See image below, where I’m showing 2 different simplified schemas for the same database for an app I am working on.
The database is for an e-commerce store. The orders collection holds the order data. The products collection holds the product catalog data, which gets copied to the products_ordered collection representing products ordered by a customer.
Users of the app will regularly be viewing orders and therefore for this use case it makes sense to go with scenario A, and have everything related to a given order be in a single document.
However users of the app will also regularly need to view all products that are on any unfulfilled order, and for this use case I feel like scenario B is better.
In the end, I believe scenario B would be better because I think that in cases where a single order is viewed, it would be pretty quick to query the products for that order from the products_ordered collection, whereas in the case when all products are viewed at once, scenario B would be significantly faster than scenario A.
What are your thoughts?
Thank you !