【发布时间】:2014-10-26 20:33:28
【问题描述】:
我来自 SQL 关系世界,有一个涉及 mongodb 架构设计的问题。
我需要表达的现实包含: 用户和月度报告(包含多个每日报告)。
我想弄清楚是否在 mongodb 中,最好将报告对象嵌入到 Users 集合中,或者有 2 个由 id 引用的单独集合。
Embedded solution:
User:{
name:
surname:
monthlyReports: [{
month: "January 2014"
dailyReport: [{
day: 1
singleReport: [
{ report1}, {report2}, ...
]
}, {
day: 2
singleReport: [
{ report1}, {report2}, ...
]
}
]
},
{
/*
february 2014
Day 1
Day 2 ...
*/
} ...
]
}
Referenced solution:
Users:{
name:
surname:
monthlyReports: [
id_reportMonth1, id_reportMonth2, ...
]
}
MonthlyReport: {
id:
month:
dailyReport: [{
day: 1
singleReport: [
{ report1 }, { report2 } ...
]
},
{
} ....
]
}
对于单用户,我需要检索单日报表、月报表和总报表。
我认为在嵌入式解决方案中,查询更简单,但创建大对象的周期较长。
另一种可能性: 创建 3 个引用集合: 用户、月报、日报。
有什么更好的方法吗? 有人建议了吗?
【问题讨论】: