# DB 스키마
## 고민해볼만한 것
- mongodb naming convensions https://typeof-undefined.tistory.com/11
```
user {
name,
id,
level,
address,
ratings : [
{
user_id, rating: "응답이 빨라요",
// 평가 항목 8개
}
],
image // url
// 판매 목록
saleList : [
post_id,
],
// 구매 목록
buyList: [
post_id,
],
// 구매 요청 목록
buyRequestList: [
post_id
]
}
categories {
name: string
}
post {
writer: user_id,
title : string,
content : string,
images: [url: string],
category: string,
comments : [
comment {
user_id,
content
}
],
buyers : [
user_id
],
state : string,
cost: number,
uploadTime,
}
```
## 문제점?
- 구매 확정을 하면 구매자를 제외한 구매 요청한 사람들의 구매 요청 리스트에서 해당 제품을 삭제해주어야할 것 같은데 그 과정이 O(구매요청한 사람 * 사람의 구매요청 리스트 수)만큼 걸릴 것 같다.
- user나 post document의 데이터 중 일부분만 가져오는 작업이 빈번하게 일어난다.
- 데이터를 분리해야할 것 같다.
- comments가 계속해서 늘어나는 문제가 생길 수 있다.
- comments를 분리해야할 것 같다.
- 평가가 추가되어 level을 계산할 때 ratings를 모두 반복해야할 수 있다.
- ratings의 각 항목을 체크한 사람의 수만 저장해놓고 rating_history에 평가한 사람의 id들을 저장해놓으면 어떨까?
- 어떤 사람이 평가를 하면 rating_history에 있는지 판단하고 없으면 ratings의 각 항목에 이 사람이 한 평가를 더한다.
# 최종 DB 스키마
```
users {
name: String,
id: String,
level: Number,
image: String,
goodRatings: [{content, value}],
badRatings: [{content, value}],
location: {lat, lon},
radius:Number
}
ratings {
content: String
state: string
}
buyrequests {
requesterId: ObjectId,
postId: ObjectId,
location: {lat, lon}
}
categories {
name: string
}
posts {
writerId: ObjectId,
buyerId: ObjectId,
title : String,
content : String,
images: [url: string],
category: String,
cost: Number,
goodRatings: [{content, value}],
badRatings: [{content, value}],
isRating : boolean,
location: {lat,lon}
uploadTime : date,
}
comments {
postId:ObjectId,
writerId:ObjectId,
content: String
}
```
###### tags: `project base`