【发布时间】:2017-04-20 16:59:33
【问题描述】:
我有 4 个收藏,例如
师,
类别,
产品组,
产品
这些都是我的数据,存储在集合中 我的部门收集数据的
{
"divisionid": "1",
"divisioncode": "0",
"divisionname": "ELECTRONICS/HOME APPLIANCE",
"divisionpoint": "2"
},
{
"divisionid": "2",
"divisioncode": "1",
"divisionname": "FOODS",
"divisionpoint": "8"
}
分类收集数据的
{
"categoryid": "1",
"divisionid": "1",
"categorycode": "34",
"categoryname": "AUDIO SYSTEM",
"categorypoint": "Null"
},
{
"categoryid": "2",
"divisionid": "1",
"categorycode": "348",
"categoryname": "DVD/VCD",
"categorypoint": "8"
}
productgroup 集合数据的
{
"productgroupid": "1",
"divisionid": "1",
"categoryid": "1",
"productgroupname": "ADAPTOR",
"productgroupcode": "6765",
"productgrouppoint": "7"
},
{
"productgroupid": "2",
"divisionid": "1",
"categoryid": "2",
"productgroupname": "WALKMAN",
"productgroupcode": "7659",
"productgrouppoint": "Null"
}
产品集合数据的
{
"productid": "1",
"divisionid": "1",
"categoryid": "1",
"productgroupid":"1",
"productname":"UNIVERSAL AC DC ADAPTER-PCS",
"productcode": "1000054",
"productpoint": "1"
},
{
"productid": "2",
"divisionid": "1",
"categoryid": "2",
"productgroupid":"2",
"productname":"WALKMAN WM#M470-PCS",
"productcode": "1000089",
"productpoint": "2"
}
我想将这 4 个集合合并为一个集合。
my expectation result:
productsummary
{
"product": {
"point": "1",
"name": "UNIVERSAL AC DC ADAPTER-PCS",
"code": "10000054",
"id" :"1"
},
"group": {
"point": "7",
"name": "ADAPTOR",
"id" :"1"
},
"category": {
"point": "0",
"name": "AUDIO SYSTEM",
"id" :"1"
},
"division": {
"point": "2",
"name": "ELECTRONICS/HOME APPLIANCE",
"id" :"1"
}
},
{
"product": {
"point": "2",
"name": "WALKMAN WM#M470-PCS",
"code": "1000089",
"id" :"2"
},
"group": {
"point": "7",
"name": "WALKMAN",
"id" :"Null"
},
"category": {
"point": "8",
"name": "DVD/VCD",
"id" :"2"
},
"division": {
"point": "2",
"name": "ELECTRONICS/HOME APPLIANCE",
"id" :"1"
}
}
当我在 ansered 代码下面执行时,我得到了错误
【问题讨论】:
-
您可以通过聚合和查找参考来做到这一点,请参阅 stackoverflow.com/questions/35813854/… 和 clusterdb.com/mongodb/… 如果您遇到任何问题,请尝试在此处发表评论。
-
我是这项技术的新手,请您帮帮我@VinodLouis
标签: javascript node.js mongodb