MongoDB电子商务产品文档设计

时间:2012-03-03 22:16:44

标签: mongodb e-commerce nosql

我正在建立一个电子商务网站,并决定尝试使用MongoDB。我的目标是实现充分的灵活性,最终,我不会受限于销售特定产品,受制于最初组合系统的限制。

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

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

                        )

                )

        )

1 个答案:

答案 0 :(得分:1)

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

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

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

没有必要“溢出”您的文档 - 我假设您的意思是为每个可能的属性存储空值?您的应用程序代码应该只检查文档中是否存在可选值,并根据该值做出渲染或业务逻辑决策。 MongoDB的优势在于其灵活性。并非所有文件都必须相同。应编写应用程序代码以处理没有所有可能字段的文档。