I would suggest moving products to a separate collection.
MongoDB data schemas are best when based on the usage requirements. In this case, a user browsing products is going to very rarely be interested in all the products that a different user is selling. Usually, they're going to be interested in products that match search criteria about price and item description or item title.
So imagine a search for the most recently posted items given your proposed data schema. Your query will have to search through every user
's array of product
subdocuments and check the timePosted
. Whereas a product
collection could easily have an index on timePosted
and not require touching unnecessary (user
and each user
's other products
) documents.
The use case for seeing a single product page is also important to consider and also indicates using a separate product
collection.
Even when you do need to show product
s that a particular user
posted, it will not be difficult in a product
collection to search by user_id
.