我正在尝试使用 mongo 的查找来创建连接。我有这三个系列。
订单跟踪
{
_id: ObejctId("59fb7815b3b8429f4750b0df"),
itemName : "Hamam Soap",
TrackLocation: [{locationId: 1, at:"2017-10-11"},
{locationId: 2,at:"2017-10-13"}],
userId : 12,
price: 20
}
位置类型
{
_id: ObejctId("59b2111345cb72345a35fefd"),
locationId : 1
productTypeName: "Warehouse"
},{
_id: ObejctId("59af8ce445cb72345a35feea"),
locationId : 2
productTypeName: "On Transit"
}
用户
{
_id: ObejctId("59a504eb6171b554c02292a9"),
"user ID":12,
"userName" : "Shahabaz Shafi",
"dateOfBirth" : "1992-01-01",
"addres": {
"country" : "India",
"state" : "Karnataka",
"city" : "Bengaluru"
}
}
并试图将其扁平化为这种输出。
{
"userName" : "Shahabaz Shafi",
"userId":12,
"dateOfBirth" : "1992-01-01",
"country" : "India",
"state" : "Karnataka",
"city" : "Bengaluru"
"locationType" : [ {productTypeName: "Warehouse",at:"2017-10-11"}, {productTypeName: "On Transit",at:"2017-10-13"}]
}
编辑:15-11-2018 更新输出
对输出列进行了一些更改
{
"userName":"Shahabaz Shafi",
"userId":12,
"dateOfBirth":"1992-01-01",
"country":"India",
"state":"Karnataka",
"city":"Bengaluru",
"items":[
{
"itemName":"Hamam Soap",
"userId":12,
"price":20,
"TrackLocation":[
{
"locationId":1,
"at":"2017-10-11",
"productTypeName":"Warehouse"
},
{
"locationId":2,
"at":"2017-10-13",
"productTypeName":"On Transit"
}
]
}
]
}
我该如何处理?
PS:我也在使用指南针