Database Reference
In-Depth Information
Scenario
Sample Embedded Document
Sample Referenced Document
Customer : {
_id : "bob",
customerName : "Bob Jones",
customerDateOfBirth
Customer : {
_id : "bob",
customerName : "Bob Jones",
customerDateOfBirth
We are building an application that allows easy
querying of customers and their accounts.
Cus-
tomer
has lots of other relationships, and in this
scenario
Account
has no other relationships.
:
:
ISODate("1973-10-07")
ISODate("1973-10-07"),
accounts : [
{
accountCode : "3281",
accountOpenDate
}
Account : {
customerId : "bob",
accountCode : "3281",
accountOpenDate
:
:
ISODate("2014-02-05")
ISODate("2014-02-05")
},
{
}
Account : {
customerId : "bob",
accountCode : "12341",
accountOpenDate
accountCode : "12341",
accountOpenDate
:
ISODate("2014-03-21")
} ] }
:
ISODate("2014-03-21")
}
Order : {
_id : "1234",
orderNumber : "AB-3429-01",
orderDate
Order : {
_id : "1234",
orderNumber : "AB-3429-01",
ISODate("2013-11-08")
:
We are building an application to allow efficient
data entry of product order information.
Order
contains over 100 fields,
Order Line
contains
over 50 fields, and
Product
contains over 150
fields. An
Order
, on average, contains 20
Order Lines
. Would you embed
Order Line
in-
to
Order
?
ISODate("2013-11-08")
}
OrderLine : {
orderId : "1234",
orderLineSequenceNumber
},
orderLines : [
{ orderLineSequenceNumber
:
:
"1",
productId : "2837",
orderLineQuantity : 15
},
{
orderLineSequenceNumber : "2",
productId : "2842",
"1",
productId : "2837",
orderLineQuantity : 15
}
OrderLine : {
orderId : "1234",