'Product Catalog with MongoDB - price model
I followed Product Catalog with MongoDB, Part 1: Schema Design but i'm not sure how to use it.
My question is how to retrieve products in a specific category with their prices?(like a simple category page in an e-commerce website)
If i put prices in the same collection with products (embed it in the product model) so with a single query i can get price for each product but i don't have as flexibility as second approach(for example variant pricing is impossible).
sample product document:
{ id: '054VA72303012P', name: 'women's kate ivory', ... prices: [{ val: 127788.33, startDate: '2018-12-31 23:59:59', endDate: '2019-2-31 23:59:59', }] }Second option is to store prices as a separate collection (as it said in the article). But i'm wondering how to retrieve products with their prices. Is it possible to do that with a single query? as MongoDB doesn't have
JOINoperation how should i select a product with the corresponding prices. Sample schemas with complete descriptions are available in the article.
Sample schemas:
product_document:{
"_id": '054VA72303012P',
"name": 'women's kate ivory',
...
}
variant_document:{
"_id": "05458452563",
"itemId": "054VA72303012P",
"name": "Width:Medium,Color:Ivory,Shoe Size:6.5",
...
}
price_document:{
"_id": "054VA72303012P_1234",
"price": "69.99",
...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
