简体   繁体   English

Node.js图像库的数据库解决方案

[英]Database solution for Node.js image gallery

I am developing a personal web-based aircraft photo gallery using Node.js, to show off my photos to friends/colleagues/etc. 我正在使用Node.js开发基于Web的个人飞机图库,以向朋友/同事/等等展示我的照片。 The server would host some hundreds or 1-2 thousands of these photos (as static files) at maximum, while their accompanying data would be stored in a database. 服务器最多可容纳数百张或1-2千张此类照片(作为静态文件),而其附带数据将存储在数据库中。

The website should not generate too much traffic (1-2 accesses only at a time). 该网站不应产生太多流量(一次只能访问1-2次)。 Its main feature would be a complex search "engine", capable of filtering and ordering photos by aircraft manufacturer, aircraft type, aircraft registration, airline, airport where the photo was taken, date of the photo, and numerous other aspects. 它的主要功能是复杂的搜索“引擎”,能够按飞机制造商,飞机类型,飞机注册,航空公司,拍摄照片的机场,照片的日期以及许多其他方面过滤和订购照片。

I have developed a relational model to serve these goals, to be implemented in a MySQL database: 我已经开发了一个关系模型来实现这些目标,并将在MySQL数据库中实现:

                               +-------+
                               | Photo |
                               +-------+
                              N |     | N
               +----------------+     +--------------+
             1 |                                     | 1
  +------------------------+            +--------------------------+
  |Aircraft | e.g. "G-CIVL"|            | Airport | e.g. "Heathrow"|
  +------------------------+            +--------------------------+
             N |                                     | N
             1 |                                     | 1
   +-----------------------+              +-----------------------+
   | Model | e.g. "747-400"|              |  City | e.g. "London" |
   +-----------------------+              +-----------------------+
             N |                                     | N
             1 |                                     | 1
 +-------------------------+         +--------------------------------+
 |Model_family | e.g. "747"|         | Country | e.g. "United Kingdom"|
 +-------------------------+         +--------------------------------+
             N |
             1 |
+----------------------------+
|Manufacturer | e.g. "Boeing"|
+----------------------------+

Every photo entry would contain information about the location it was taken at (Airport - city - country "branch") and the aircraft shown in the photo (Aircraft - model - model_family - manufacturer "branch"). 每个照片条目都将包含有关拍摄地点的信息(机场-城市-国家“分支机构”)和照片中显示的飞机(飞机-模型-模型_家庭-制造商“分支机构”)。

As I've mentioned before, the visitors should be able to filter photos by any columns of these tables, requiring different joins in the database query for different filtering options. 如前所述,访问者应该能够按这些表的任何列过滤照片,要求数据库查询中具有不同的联接以提供不同的过滤选项。 Examples: 例子:

  1. The user is looking for photos taken in a certain country. 用户正在寻找在特定国家/地区拍摄的照片。 The SELECT query returning the corresponding image data should join the Photo, Airport, City and Country tables. 返回相应图像数据的SELECT查询应加入Photo,Airport,City和Country表。
  2. The user is filtering photos by a certain aircraft model. 用户正在按某种飞机模型过滤照片。 The SELECT query would have to join Photo and Model tables only. SELECT查询将只需要联接Photo和Model表。

The question is even more complex if the user is filtering photos by multiple (or even more) aspects at the same time. 如果用户同时按多个(或更多)方面过滤照片,则问题将变得更加复杂。

For this reason, a complex application-level SQL query building algorithm would be needed, which would take the aforementioned table structure into account. 因此,需要一个复杂的应用程序级SQL查询构建算法,该算法将考虑上述表结构。

My questions are: 我的问题是:

  • Is the mentioned method (complex SQL string building algorithm) a good approach to the problem? 提到的方法(复杂的SQL字符串构建算法)是解决该问题的好方法吗?

  • Or should I just join all the tables together regardless of the user's filtering options? 还是应该将所有表都联接在一起,而不考虑用户的过滤选项? (seems to be a serious performance tradeoff for better code maintainability) (似乎是为了提高代码可维护性而进行的严重性能折衷)

  • Or would a NoSQL solution like MongoDB with a flatter (and denormalized) model more adequate for this task? 还是像MongoDB这样的NoSQL解决方案(具有更平坦(和非规范化)的模型)更适合此任务? Not having to set up different joins for different filtering options seems to be a huge plus. 不必为不同的过滤选项设置不同的联接似乎是一大优势。 It is very unlikely for the stored data to be updated or deleted, therefore denormalization might not be a serious problem. 存储的数据极不可能被更新或删除,因此非规范化可能不是一个严重的问题。

Thank you for your help in advance. 提前谢谢你的帮助。

I haven't used MYSQL that much but in NoSQL ( Mongodb ) 我没有用过MYSQL ,但是在NoSQL( Mongodb )中使用了

you can get data structure something like this and you can search based on every parameter 您可以获得类似这样的数据结构,并且可以基于每个参数进行搜索

[
  {
    "_id": 0,
    "Airport": "Heathrow",
    "city": "London",
    "country": "United Kingdom",
    "Aircraft": "G-CIVL",
    "model": "747-400",
    "model_family": "747",
    "manufacturer": "Boeing",
    "photo_url": "http://www.dummy-url/dakshdajk8sdjkhs8ds8dh8sd8sdj8s.png"
  },
  {
    "_id": 1,
    "Airport": "Heathrow",
    "city": "London",
    "country": "United Kingdom",
    "Aircraft": "G-CIVL",
    "model": "747-400",
    "model_family": "747",
    "manufacturer": "Boeing",
    "photo_url": "http://www.dummy-url/dakshdajk8sdjkhs8ds8dh8sd8sdj8s.png"
  }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM