我有一个名为的集合Org
,其中包含Resources
在团队之间共享的资源(模式)(Teams
模式)
{
"_id": ObjectId("511cfbc9d593e5290c000005"),
"name": "Some org name",
"resources": [
{
"_id": ObjectId("511cfbc9d593e5290c000007"),
"name": "Printer1",
/* mongoose.Schema.Types.Mixed */
"details": {
"ip": "192.168.1.99"
}
}, {
"_id": ObjectId("511cfbc9d593e5290c000008")
"name": "Fax1",
"details": {
"number": "XXXXXXXXXXXX"
}
}
],
"teams" : [
{
"_id": ObjectId("511cfbc9d593e5290c000012"),
"name": "sales",
/*"resources": {type: [mongoose.Schema.Types.ObjectId], ref: 'Resources'}*/
"resources": [ObjectId("511cfbc9d593e5290c000007")]
}, {
"_id": ObjectId("511cfbc9d593e5290c000006"),
"name": "developer",
"resources": [ObjectId("511cfbc9d593e5290c000007"), ObjectId("511cfbc9d593e5290c000008")]
}
]
}
还有一个People
集合,它是团队的一部分。
{
"name": "Peter",
"designation": "senior s/w engg.",
"contact": {}
/*"teams": {type: [mongoose.Schema.Types.ObjectId], ref: 'Teams'}*/
"teams": [ObjectId("511cfbc9d593e5290c000006")]
}
现在,如果资源或团队发生更改,我想跳过多次更新,所以我没有使用嵌套文档。我无法ref
Resources
从架构中进行Teams
架构。结果,要获得以下结果,我必须通过非常复杂的聚合函数。
{
"name": "Peter",
"designation": "senior s/w engg.",
"contact": {}
"teams": [{
"_id": ObjectId("511cfbc9d593e5290c000006"),
"name": "developer",
"resources": [{
"_id": ObjectId("511cfbc9d593e5290c000007"),
"name": "Printer1",
"details": {
"ip": "192.168.1.99"
}
}, {
"_id": ObjectId("511cfbc9d593e5290c000008")
"name": "Fax1",
"details": {
"number": "XXXXXXXXXXXX"
}
}]
}]
}
有人可以建议我是否在数据库设计中做错了什么。有没有更简单的方法?