我有一个电子商务应用程序,其中的产品有多个变体,因此,变体存储在每个Product对象的数组中。
[
{
title: "Test"
description: "test description",
....
....
variants: [
{
color: "red",
size: "L"
....
....
price: 500
},
{
color: "red",
size: "M"
....
....
price: 500
},
{
color: "red",
size: "S"
....
....
price: 500
},
]
}
]
有没有一种方法可以通过ID过滤这些产品变体,并作为变体的普通数组返回,忽略它们来自不同的父代,但使用父代详细信息?
[
{
color: "red",
size: "L"
....
....
price: 500,
parent: {
title: "Test"
description: "test description"
}
},
{
color: "red",
size: "M"
....
....
price: 500,
parent: {
title: "Test"
description: "test description"
}
},
{
color: "red",
size: "S"
....
....
price: 500,
parent: {
title: "Test"
description: "test description"
}
},
{
color: "orange",
size: "S"
....
....
price: 500,
parent: {
title: "Test 2"
description: "test description 2"
}
},
]
1条答案
按热度按时间0kjbasz61#
查询1
parent
的字段,其中包含根目录中的字段(variants
除外)variants
variants
中添加parent
字段的Mapvariants
并替换根Playmongo
查询2
Playmongo