Hi all, I'm facing a problem with "order - product" data
Denormalized data may look like:
A product:
{
"_id" : productId,
"name" : name,
"price" : price,
"desc" : description
}
An order:
{
"_id" : orderId,
"user" : userInfo,
"products" : [
{
"_id" : productId1,
"name" : name1,
"price" : price1
},
{
"_id" : productId2,
"name" : name2,
"price" : price2
},
{
"_id" : productId3,
"name" : name3,
"price" : price3
}
]
}
-
With this design we're having two problems:
- I often need to do aggregation query in nested document (product), and it is very slow (about 85% slower in our benchmark) compared to the similar query in the product index only. For example: Show the most popular product or show all product group by total revenue
- In many case products in the order must update frequently because we can't receive full order once at a time (business domain)
-
With the parent-child model, you know, I'm aware of join. I haven't explicitly tested it yet, how about grouping order-product by order or get full order-product in one document ?
-
We can create two indices for this: one for product and one for order (with full nested product) and additional data for aggregation too. But this require much of work and duplicate data too!
Can you give me some advice? Thank you very much!