How to structure database design for a simple photo album in couchdb?

I want to try CouchDb by developing a small PhotoAlbum application where different users can have many albums with many photos. Am I doing this right if I create a document for each user that contains an array of albums that contains photos with attachments?

{ 
    user: "Dominik", 
    albums: [ 
        { name: "USA Trip", photos: 
            [ 
                { title: "Golden Gate Bridge", _attachments: [ the photo ] },
                { another photo } 
            ]
        },
        { ...} ] 
}

or is there another good way to do this?

or is it better to store users, albums and photos in different documents? Will this require foreign keys, as in mysql?

{ type: "user", name: "Dominik", albums: [ "a1", "a2", "a3" ] }
{ type: "album", _id: "a1", title: "USA Trip", photos: [ "p1", "p2" ... ] }
{ type: "photo", _id: "p1", _attachments: {...}, title: "Golden Gate Bridge" }

...

or vice versa:

{ type: "user", _id: "u1", name: "Dominik" }
{ type: "album", _id: "a1", title: "USA Trip", user: "u1" }
{ type: "photo", _id: "p1", _attachments: {...}, title: "Golden Gate Bridge", album: "a1" }
+3
source share
2 answers

, . . , memcached-server 1 "--" ( CouchDB memcached), .

, , . , , , .

+1

1999 . :

  • , Apache CouchDB — . - .
  • CouchDB , . validate_doc_update , , . ( CouchDB , .)
+1

Source: https://habr.com/ru/post/1790942/


All Articles