Skip to content

DB 나누기

최홍일 edited this page Dec 17, 2020 · 7 revisions
  • 필요할 것 같은 것들을 종류로 나누자
  • EMBEDED DOCUMENT vs REFERENCE중 어떤식으로 사용할지..?
  • UPDATE 가 발생할 경우는 ??
    • UPDATE가 자주 발생할까 ??
      • default값을 정해서 초기 setting으로 넣어주고, 그 외에는 document에 추가만 해주자

최소단위로 DB를 분리해보자

# user
{
	(_id)
	id : string, required,
	name : string, required,
	pwd : string
	accountbook : [_id ...]
}
# account book
{
	(_id)
	name : string
        startday : number
	description : string
	transaction : [_id]
}
# transaction
{
	(_id)
	content : string
	type : string (수입/지출)
	cost : number
	date : date
}
# category
{
	(_id)
	name : string
        type : string
	icon : number	
}
# payment
{
	(_id)
	card : number
	description : string
        color : string
}

첫 DB 설계

# user 
{
    (_id)
    id : string
    name : string
    pwd : string
}
#default_category
{
    (_id)
    name : string
    type : string
    icon : number
}
#default_payment
{
    (_id)
    card : number
    description : string
    color : string
}
# account book
{
    (_id)
    name : string
    startday : string
    description : string
    code : string
    category: [
        {
            (_id)
            name : string
            type : string
            icon : number	
        }
    ]
    payment: [
        {
            (_id)
            card : number
            description : string
            color : string
        }
    ]
    user: [
        {
          (_id)
          id : string
          name : string
          pwd : string
        }
    ]
    transaction : [
        {
            (_id)
            content : string
            type : string (수입/지출)
            cost : number
            date : date
            category: {
                name : string
                type : string
                icon : number
            }
            payment: {
                card: number
                description : string
            }
        } ...
    ]
}

변경후 DB

Users
{
	_id
	userid : string
	name : string
	profile : string
	social : string
}
Accountbooks
{
	_id
	name : string
	code : string
	startday : string
	description : string
	categories : categories[] 				// embedded Document
	paymentmethods : paymentmethods[] 		// embedded Document
	users : usersembedded Document[]		// embedded Document
}
Transactions
{
	_id
	content : string
	type : string
	cost : number
	date : date
	category : {category}
	paymentmethod : {paymentmethod}
	accountBook : accountbook._id  // reference
}
Categories
{
	_id
	name : string
	type : string
	icon : number
}
Payments
{
	_id
	name : string
    color : string
    description : string
}
Default_payment_methods
{
	_id
	name : string
	color : string
}
Default_categories
{
	_id
	name : string
	type : string
	icon : number
}
Clone this wiki locally