-
데이터 모델링
schema 설계 시, 고려사항들은 다음과 같다.
- 사용자 요구에 따라 schema를 디자인한다.
- 객체들을 함께 사용하게 된다면 한 Document에 합쳐서 사용한다(예: 게시물-덧글). 그렇지 않으면 따로 사용한다 (그리고 join 을 사용하지 않는걸 확실히 해둔다.)
- 읽을 때, join 하는게 아니라 데이터를 작성 할 때 join 한다.
예제
위의 그림은 RDBMS로 게시판 기능을 구현하는 것이다. 3개의 테이블로 나눠져있지만, NoSQL에서는 하나의 Document에 넣는다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters{ _id: POST_ID, title: POST_TITLE, content: POST_CONTENT, username: POST_WRITER, tags: [ TAG1, TAG2, TAG3 ], time: POST_TIME comments: [ { username: COMMENT_WRITER, mesage: COMMENT_MESSAGE, time: COMMENT_TIME }, { username: COMMENT_WRITER, mesage: COMMENT_MESSAGE, time: COMMENT_TIME } ] } 실제 프로젝트
위의 그림을 NoSQL 모델링을 해보았다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersUser{ id email name password } Board{ id user: User title: string content: string active: int comment: Comment Like: [User] } Comment{ id user: User board: Board content: string ref_comment: Comment } Like{ id user: User Board: Board }