【问题标题】:MongoDB ecommerce product document designMongoDB电子商务产品文档设计
【发布时间】:2012-03-03 22:16:44
【问题描述】:

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

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

  • 在目录中,我想拆分具有颜色属性的产品,以便每个颜色作为单独的产品呈现。我可以使用我当前的文档设计通过 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
                                )

                        )

                )

        )

【问题讨论】:

    标签: mongodb e-commerce nosql


    【解决方案1】:

    我认为您的设计可以正常工作,尽管我认为不需要将必需和可选属性分离到单独的子文档中。

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-01-28
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      • 2017-12-16
      • 2019-02-22
      • 1970-01-01
      • 2021-03-15
      相关资源
      最近更新 更多