How would you model this database?

I am currently taking M320, and obviously as I am following the syllabus I have in mind the first database I need to design in MongoDB.

See image below, where I’m showing 2 different simplified schemas for the same database.

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.

It is best to keep the question of this forum to be about course specific subjects and issues.

For questions outside the scope of the course it is better to go to

1 Like

Noted, thank you.