【发布时间】:2012-05-19 23:42:18
【问题描述】:
我有一个使用 MongoDB + GridFS 的电子商务网站。 每个产品最多可以有 5 张图片。 每张图片都有 3 个不同大小的缩略图。
为此,我需要关于最佳数据库结构的建议。
目前我正在考虑在每个产品中存储图像 ID 和拇指 ID(来自 GridFS 的 ID):
{
'_id': 1,
'title': 'Some Product',
'images': [
{'id': '11', thumbs: {'small': '22', 'medium': '33'},
{'id': '44', thumbs: {'small': '55', 'medium': '66'}
]
}
或者将路径存储在 GridFS 中会更好吗?
{
'_id': '111',
'filename': '1.jpg',
'path': 'product/988/image/111/'
},
{
'_id': '222',
'filename': '1.jpg',
'path': 'product/988/image/111/thumbnail_small'
},
{
'_id': '333',
'filename': '1.jpg',
'path': 'product/988/image/111/thumbnail_large'
}
更新:GridFS 中的“路径”字段是“假”路径,而不是真实路径。只是一种快速查找所有相关文件的方法。拥有 1 个索引字段比使用复合索引的多个字段便宜。
【问题讨论】:
标签: image mongodb thumbnails gridfs