I'm creating a photo gallery SPA with angularJS (front & back) and nodejs (server). I'm asking myself which type of database I should use to store the gallery/photo knowing :
Photo
and Gallery
Gallery
will contain either another Gallery
or a Photo
(infinite stacking of gallery possible in theory ...) photo
/ gallery
to another Gallery
easily, or a full branch (move a tree of 4 nested gallery to another one) related SQL structure:
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.
How would you structure that with a noSQL databases like 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 ?
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"
}
}
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.