在 NoSQL 中存储相册的内容
进一步回答这个问题:
网络照片库的正确 NoSQL 数据架构< /p>
在 MySQL 中,检索相册的内容看起来像这样:
SELECT photos.*, albums.album_title
FROM photos, albums_to_photos, albums
wHERE albums_to_photos.photo_id = photos.photo_id AND
albums_to_photos.album_id = albums.album_id AND
album_title = 'Family Vacation'
这将从相册“家庭度假”中检索所有照片的列表
我想到的一种方法是创建一个名为“相册”的表并存储照片 ID值字段内的所有照片。例如:
{_id:'Family Vacation',
values:'25, 512, 6172, 16923, 168253, 79185892'}
然后对每个值执行多重选择,以查找实际照片项目的照片 ID。这是一个好方法吗?
Further to this question:
In MySQL, retrieving the contents of an album would have looked like this:
SELECT photos.*, albums.album_title
FROM photos, albums_to_photos, albums
wHERE albums_to_photos.photo_id = photos.photo_id AND
albums_to_photos.album_id = albums.album_id AND
album_title = 'Family Vacation'
This would have retrieved a list of all photos from the album "Family Vacation"
One way I was thinking of is to create a table called "albums" and to store the photo ids of all the photos within the value field. For example:
{_id:'Family Vacation',
values:'25, 512, 6172, 16923, 168253, 79185892'}
And then performing a multi select for each of those values to lookup the photo ids to actual photo items. Is this a good approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
单独存储每张照片,如果您想在某个时候添加更多照片信息(例如标题),则更容易管理。还可以考虑使用 ID 来引用您的相册。然后你可以这样做:
->find(array( "album" => "Family Vacation" ))
Store each photo separately, if you want to at some point add more photo info such as titles it's easier to manage. Also consider using id's to reference your albums. Then you can do something like:
->find(array( "album" => "Family Vacation" ))
Stur,如果我错了,请纠正,但是按列过滤会进行全表扫描,对吧?
如果是这样,我相信 Ensnare 提出的解决方案在更大的数据下会更好地工作。
Ensnare,假设对于标签,您使用 dynamodb,您可以使用一组整数作为照片 ID,但您需要遵守每行 64kb 的限制。
您还可以创建二级索引,使用相册名称作为主键,使用 photoid 作为范围键。
Stur, correct if i'm wrong, but filter by a column will do a full table scan right?
If so, i believe that the solution presented by Ensnare will work better with a bigger data.
Ensnare, assuming for the tag, you use dynamodb, you can use an Set of Integer for the photo ID, but you will need to work with the 64kb per row limit.
You can also create an secondary index, using the album name as primary key, and photoid as range key.