gpt4 book ai didi

MongoDB电商产品文档设计

转载 作者:可可西里 更新时间:2023-11-01 09:15:52 24 4
gpt4 key购买 nike

我正在构建一个电子商务网站,并决定试用 MongoDB。我的目标是实现完全的灵 active ,这样到最后,我就不会受制于销售特定产品,而受到系统最初组合方式的限制。

因此,灵 active 的目标是,我必须能够根据属性创建产品。外汇。颜色、制造商、速度等。所有属性都必须是可选的。用户可以创建新的属性,有些是默认的系统属性(不可删除)。根据属性的配置,它将与“基础”产品或可配置产品分层。

  • 在目录中,我想拆分具有颜色属性的产品,以便每种颜色作为单独的产品呈现。我可以使用我当前的文档设计通过 MongoDB 实现这一目标吗?
  • 我得出的结论是,在从 MongoDB 中选择产品时,在展示之前,我必须“填满”我的文档,或者做大量的数据映射。我错了吗?
  • 考虑到一些产品有选项(颜色、尺寸)而另一些没有,那么进行库存管理的最佳和最有效的方法是什么?

如我的示例所示,我在属性下存储了普通属性,在文档选项下可以找到“必需”属性。

我的产品文档能否以某种方式改进,使事情变得更容易?我担心我在某件事上做得过头或做得不够,因为我发现我的想法因使用关系数据库而“受损”。

最好的问候

(
[type] => Product
[sku] => elin/4191
[name] => Array
(
[da] => Sko - Elin
[en] => Shoes - Elin
)

[url_key] => Array
(
[da] => sko-elin
[en] => 1-744
)

[categories] => Array
(
)

[shops] => Array
(
[0] => 1
)

[images] => Array
(
[0] => test.jpg
[1] => test1.jpg
)

[options] => Array
(
[0] => Array
(
[color] => Array
(
[da] => Sort
[en] => Black
)

[size] => Array
(
[da] => Lille
[en] => Small
)

[shipping] => Array
(
[weight] => 0
[width] => 0
[height] => 0
[depth] => 0
)

[pricing] => Array
(
[price] => 899
[retail] => 0
[cost] => 333
[vat] => 25
[special] => Array
(
[price] => 0
[from] => new Date()
[to] => new Date()
[pct_savings] => 100
[savings] => 0
)

)

)

[1] => Array
(
[color] => Array
(
[da] => Sort
[en] => Black
)

[size] => Array
(
[da] => Medium
[en] => Medium
)

[shipping] => Array
(
[weight] => 0
[width] => 0
[height] => 0
[depth] => 0
)

[pricing] => Array
(
[price] => 899
[retail] => 0
[cost] => 333
[vat] => 25
[special] => Array
(
[price] => 0
[from] => new Date()
[to] => new Date()
[pct_savings] => 100
[savings] => 0
)

)

)

[2] => Array
(
[color] => Array
(
[da] => Orange
[en] => Orange
)

[size] => Array
(
[da] => Lille
[en] => Small
)

[shipping] => Array
(
[weight] => 0
[width] => 0
[height] => 0
[depth] => 0
)

[pricing] => Array
(
[price] => 899
[retail] => 0
[cost] => 333
[vat] => 25
[special] => Array
(
[price] => 0
[from] => new Date()
[to] => new Date()
[pct_savings] => 100
[savings] => 0
)

)

)

[3] => Array
(
[color] => Array
(
[da] => Orange
[en] => Orange
)

[size] => Array
(
[da] => Medium
[en] => Medium
)

[shipping] => Array
(
[weight] => 0
[width] => 0
[height] => 0
[depth] => 0
)

[pricing] => Array
(
[price] => 899
[retail] => 0
[cost] => 333
[vat] => 25
[special] => Array
(
[price] => 0
[from] => new Date()
[to] => new Date()
[pct_savings] => 100
[savings] => 0
)

)

)

)

[attributes] => Array
(
[designer] => Array
(
[name] => Array
(
[da] => Manufacturer
[en] => Manufacturer
)

[type] => text
[visible] => 1
[required] => false
[value] => Array
(
[da] => FunnyShirts
[en] => FunnyShirts
)

)

)

)

最佳答案

我认为您的设计会很好,尽管我认为没有必要将必需属性和可选属性分离到单独的子文档中。

我不懂 PHP,但要在显示时将每种颜色视为单独的产品,您可以执行以下操作:

product = db.products.findOne({sku: "..."})
for color in product.colors:
# render the product with the color

没有必要“填满”您的文档——我假设您的意思是为每个可能的属性存储空值?您的应用程序代码应该简单地检查文档中是否存在可选值,并据此做出呈现或业务逻辑决策。 MongoDB 的优势之一是它的灵 active 。并非所有文件都必须相同。您的应用程序代码应编写为处理不包含所有可能字段的文档。

关于MongoDB电商产品文档设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9550361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com