[MongoDB] 몽고디비를 위한 데이터 모델링
# 몽고디비를 위한 데이터 모델링
>> Rich Docuemnt = Embedded Document + Extend Document
- Embedded Document : 처음부터 Main Document에 내장시키는 경우
- Extend Document : update를 통해 Main Document에 내장시키는 경우
- 강한관계가 있을 경우 Rich Document로 설계함
db.ord.insert(
{ ord_id : "2012-09-0001",
customer_name: "Won",
emp_name : "Magee",
total: "601100",
payment_type: "Credit",
order_filled: "Y",
item_id : [{item_id:"1",
product_nem:"Bunny Boots",
item_price:"135",
qty: "500"
}
]
})
db.ord.drop();
db.ord.insert(
{ ord_id : "2012-09-0001",
customer_name: "Won",
emp_name : "Magee",
total: "601100",
payment_type: "Credit",
order_filled: "Y"
})
db.ord.update(
{ord_id:"2012-09-0001"},
{$set: {
item_id : [{item_id:"1",
product_nem:"Bunny Boots",
item_price:"135",
qty: "500"
}
]
}
}
)
>> Link
- RDBMS의 Relationship과 유사
- object id로 연결함.
db.ord.insert(
{ ord_id : "2012-09-0001",
customer_name: "Won",
emp_name : "Magee",
total: "601100",
payment_type: "Credit",
order_filled: "Y"
})
db.ord_detail.insert(
{ ord_id : "2012-09-0001",
item_id : [{item_id:"1",
product_nem:"Bunny Boots",
item_price:"135",
qty: "500"
}
],
ordid_id : ObjectId("58d21b1a9a64ba7acc1003c1")
}
)
o = db.ord.findOne({ord_id:"2012-09-0001"})
db.ord_detail.findOne({ordid_id:o._id})
>>
- EOF -