我正在建设一个电子商务网站,并决定尝试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
)
)
)
)发布于 2012-03-05 19:14:44
我认为您的设计会很好,尽管我不认为需要将必需的和可选的属性分离到单独的子文档中。
我不知道PHP,但是要在显示时将每种颜色作为一个单独的产品来处理,您可以这样做:
product = db.products.findOne({sku: "..."})
for color in product.colors:
# render the product with the color没有必要“填写”您的文档--我想您是指为每个可能的属性存储空值吗?应用程序代码应该简单地检查文档中是否存在一个可选的值,并在此基础上做出其呈现或业务逻辑决策。MongoDB的优势之一是灵活性。并不是所有的文件都是一样的。应该编写应用程序代码来处理没有所有可能字段的文档。
https://stackoverflow.com/questions/9550361
复制相似问题