<tfoot id='UFlcV'></tfoot>

      <bdo id='UFlcV'></bdo><ul id='UFlcV'></ul>

    <i id='UFlcV'><tr id='UFlcV'><dt id='UFlcV'><q id='UFlcV'><span id='UFlcV'><b id='UFlcV'><form id='UFlcV'><ins id='UFlcV'></ins><ul id='UFlcV'></ul><sub id='UFlcV'></sub></form><legend id='UFlcV'></legend><bdo id='UFlcV'><pre id='UFlcV'><center id='UFlcV'></center></pre></bdo></b><th id='UFlcV'></th></span></q></dt></tr></i><div id='UFlcV'><tfoot id='UFlcV'></tfoot><dl id='UFlcV'><fieldset id='UFlcV'></fieldset></dl></div>

    <small id='UFlcV'></small><noframes id='UFlcV'>

        <legend id='UFlcV'><style id='UFlcV'><dir id='UFlcV'><q id='UFlcV'></q></dir></style></legend>

        用于 Web 照片库的正确 NoSQL 数据架构

        时间:2023-09-14

          <tbody id='pFIrK'></tbody>

            • <bdo id='pFIrK'></bdo><ul id='pFIrK'></ul>
              <i id='pFIrK'><tr id='pFIrK'><dt id='pFIrK'><q id='pFIrK'><span id='pFIrK'><b id='pFIrK'><form id='pFIrK'><ins id='pFIrK'></ins><ul id='pFIrK'></ul><sub id='pFIrK'></sub></form><legend id='pFIrK'></legend><bdo id='pFIrK'><pre id='pFIrK'><center id='pFIrK'></center></pre></bdo></b><th id='pFIrK'></th></span></q></dt></tr></i><div id='pFIrK'><tfoot id='pFIrK'></tfoot><dl id='pFIrK'><fieldset id='pFIrK'></fieldset></dl></div>

            • <legend id='pFIrK'><style id='pFIrK'><dir id='pFIrK'><q id='pFIrK'></q></dir></style></legend>

                <small id='pFIrK'></small><noframes id='pFIrK'>

                  <tfoot id='pFIrK'></tfoot>
                1. 本文介绍了用于 Web 照片库的正确 NoSQL 数据架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在寻找为照片库的 NoSQL 存储构建合适的数据结构.在我的 Web 应用程序中,一张照片可以是 1 个或多个相册的一部分.我有使用 MySQL 的经验,但几乎没有使用过键值存储.

                  I'm looking to build an appropriate data structure for NoSQL storage of a photo gallery. In my web application, a photo can be part of 1 or more albums. I have experience with MySQL, but almost none with key-value storage.

                  使用 MySQL,我将设置 (3) 个表,如下所示:

                  With MySQL, I would have set up (3) tables as follows:

                  photos (photo_id, title, date_uploaded, filename)
                  albums (album_id, title, photo_id)
                  album_photo_map (photo_id, album_id)
                  

                  然后,要检索 5 张最新照片的列表(带有相册数据),查询如下:

                  And then, to retrieve a list of the 5 latest photos (with album data), a query like this:

                  SELECT *
                  FROM albums, photos, album_photo_map
                  WHERE albums.album_id = album_photo_map.album_id AND
                                  photos.photo_id = album_photo_map.photo_id
                  ORDER BY photos.date_uploaded DESC LIMIT 5;
                  

                  如何使用 NoSQL 键值对数据库完成类似的查询?(特别是亚马逊的 DynamoDB.)存储会是什么样子?索引如何工作?

                  How would I accomplish a similar query using a NoSQL key-value pair database? (Specifically, Amazon's DynamoDB.) What would the storage look like? How would the indexing work?

                  推荐答案

                  使用 mongodb lingo,您的集合可能如下所示:

                  Using mongodb lingo, your collections could look like this:

                  photos = [
                      {
                          _id: ObjectId(...),
                          title: "...",
                          date_uploaded: Date(...),
                          albums: [
                              ObjectId(...),
                              ...
                          ]
                      },
                      ...
                  ]
                  
                  albums = [
                      {
                          _id: ObjectId(...),
                          title: "..."
                      }
                  ]
                  

                  查找 5 张最新照片的方法如下:

                  Finding the 5 newest photos would be done like this:

                  > var latest = db.photos.find({}).sort({date_uploaded:1}).limit(5);
                  

                  mongo 中没有服务器端连接,因此您必须像这样获取所有最新专辑:

                  There's no server-side joins in mongo, so you'd have to fetch all the latest albums like this:

                  > var latest_albums = latest.find({}, {albums: 1});
                  

                  当然,那你必须把它归结为一个集合.

                  Of course, then you have to boil this down into a set.

                  如果您只是将相册嵌入照片文档中,实际上会更容易,因为它们很小:

                  It's actually easier if you just embed the album inside the photo documents, since they're small:

                  photos = [
                      {
                          _id: ObjectId(...),
                          title: "...",
                          date_uploaded: Date(...),
                          albums: [
                              {name: "family-vacation-2011", title: "My family vacation in 2010"},
                              ...
                          ]
                      },
                      ...
                  ]
                  

                  那么查询也是一样的,只是你不必加入.查找相册中的所有照片如下所示:

                  Then querying is the same, but you don't have to join. Finding all photos in an album looks like:

                  > db.photos.find({albums:{$elemMatch:{name: "family-vacation-2011"}}});
                  

                  这篇关于用于 Web 照片库的正确 NoSQL 数据架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:是否有任何用于 NoSQL 数据库架构迁移的工具? 下一篇:Python 对象数据库列表

                  相关文章

                  最新文章

                      <i id='FNEwZ'><tr id='FNEwZ'><dt id='FNEwZ'><q id='FNEwZ'><span id='FNEwZ'><b id='FNEwZ'><form id='FNEwZ'><ins id='FNEwZ'></ins><ul id='FNEwZ'></ul><sub id='FNEwZ'></sub></form><legend id='FNEwZ'></legend><bdo id='FNEwZ'><pre id='FNEwZ'><center id='FNEwZ'></center></pre></bdo></b><th id='FNEwZ'></th></span></q></dt></tr></i><div id='FNEwZ'><tfoot id='FNEwZ'></tfoot><dl id='FNEwZ'><fieldset id='FNEwZ'></fieldset></dl></div>

                    1. <small id='FNEwZ'></small><noframes id='FNEwZ'>

                      <tfoot id='FNEwZ'></tfoot><legend id='FNEwZ'><style id='FNEwZ'><dir id='FNEwZ'><q id='FNEwZ'></q></dir></style></legend>

                        <bdo id='FNEwZ'></bdo><ul id='FNEwZ'></ul>