在 NoSQL 中存储相册的内容

发布于 2025-01-02 18:59:50 字数 697 浏览 3 评论 0原文

进一步回答这个问题:

网络照片库的正确 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:

Proper NoSQL data schema for web photo gallery

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傻比既视感 2025-01-09 18:59:50
{
   "_id": ObjectId("4f30153eecd1ab7c49ded566"),
   "album": "Family Vacation",
   "photo": "25"
},
{
   "_id": ObjectId("4f30153eecd1ab7c49ded565"),
   "album": "Family Vacation",
   "photo": "512"
}

单独存储每张照片,如果您想在某个时候添加更多照片信息(例如标题),则更容易管理。还可以考虑使用 ID 来引用您的相册。然后你可以这样做:

->find(array( "album" => "Family Vacation" ))

{
   "_id": ObjectId("4f30153eecd1ab7c49ded566"),
   "album": "Family Vacation",
   "photo": "25"
},
{
   "_id": ObjectId("4f30153eecd1ab7c49ded565"),
   "album": "Family Vacation",
   "photo": "512"
}

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" ))

魄砕の薆 2025-01-09 18:59:50

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文