从mongodb 3.4.6中的多个文档合并属性
我想将以下所有文档合并为1个文档,在预期响应中具有以下属性。我正在使用mongodb 3.4.6
注意:我尝试使用$ mergeObjects&与mongodb版本3.4.6不兼容。有人可以建议。
预期:
{
"_id": "76778",
"Colour": "GREY",
"size":"Small"
"Attr": [{
"AttrId": 1,
"AttrText" : "12270"
},
{
"AttrId" : 2,
"AttrText": "12271"
},
{
"AttrId": 7,
"AttrValueId": "44"
},
{
"AttrId": 8,
"AttrDate": "2009-04-15T01:00:00Z"
}
]
}
来自mongodb的源文件
文档1
{
"_id" : "Product_76778",
"ProductDesc" : {
"ProdNo" : "76778",
"Colour" : "GREY",
"size":"Small"
},
"ProductType" : "SKU",
"ProdNo" : "76778",
"OrderLevel" : 1
}
Doc 2
{
"_id" : "ProductAttr_76778_2",
"ProdNo" : "76778",
"AttrId" : 1,
"AttrText" : "12270",
"OrderLevel" : 2
}
Doc 3
{
"_id" : "ProductAttr_76778_3",
"ProdNo" : "76778",
"AttrId" : 2,
"AttrText" : "12271",
"OrderLevel" : 2
}
Doc 4
{
"_id" : "ProductAttr_76778_4",
"ProdNo" : "76778",
"AttrId" : 7,
"AttrValueId" : "44",
"OrderLevel" : 2
}
Doc 5
{
"_id" : "ProductAttr_76778_5",
"ProdNo" : "76778",
AttrId" : 8,
"AttrDate" : "2009-04-15T01:00:00Z",
"OrderLevel" : 2
}