简体   繁体   English

NoSQL数据库用于关系数据结构

[英]NoSQL database for relational data structure

I'm creating a photo gallery SPA with angularJS (front & back) and nodejs (server). 我正在使用angularJS(正面和背面)和nodejs(服务器)创建一个照相馆SPA。 I'm asking myself which type of database I should use to store the gallery/photo knowing : 我问自己应该使用哪种类型的数据库来存储图库/照片:

  • I'll have two main classes : Photo and Gallery 我将有两个主要班级: PhotoGallery
  • A Gallery will contain either another Gallery or a Photo (infinite stacking of gallery possible in theory ...) 一个Gallery将包含另一个Gallery或一张Photo (理论上可能无限堆叠画廊...)
  • Easy data manipulation, for example, I need the ability to move a photo / gallery to another Gallery easily, or a full branch (move a tree of 4 nested gallery to another one) 轻松进行数据操作,例如,我需要能够轻松地将photo / gallery移动到另一个Gallery ,或将其完全分支(将4个嵌套画廊的树移动到另一个)

related SQL structure: 相关的SQL结构:

Photo (photo_id, title, filename, gallery_id) //gallery_id is a foreign key to Gallery table
Gallery (gallery_id, title, parent_id) //parent_id is NULL when no parent (root gallery)

This data structure is quite simple but relational, so using a SQL database like postgresql with NodeJS would be OK. 这种数据结构非常简单,但是具有关系性,因此可以将带PostJS的SQL数据库与NodeJS一起使用。

How would you structure that with a noSQL databases like mongoDB ? 您如何使用noSQL数据库(如mongoDB)来结构化它? (maybe with my relational structure data it's totally out of the question ?) (也许就我的关系结构数据而言,这完全不可能了吗?)

Is it a case where traditional relational SQL databases is preferable ? 是传统关系型SQL数据库更可取的情况吗?

Thanks 谢谢

使用mongoDB来保留嵌套结构,因为它将启用索引到n级并也允许对那些索引进行查询。

Here is the example to insert a record into a collection called photogallery. 这是将记录插入称为相册的集合的示例。 You need not have to pre-create collection. 您不必预先创建集合。

db.photogallery.insert(
{
 photo_id: "1",
 phototitle: "phototitle",
 filename: "filename",
 gallery: {
    gallerytitle: "gallerytitle",
    parentgallery: "parentgallery"
 }
}
)

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

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