【发布时间】:2019-12-18 00:59:51
【问题描述】:
我在名为 fieldlist 的集合中有以下示例文档
{
"_id" : ObjectId("5de3aafd2e46e531a45e441a"),
"version" : 1,
"isvalid" : true,
"columnname_datatype" :
{
"col1" : "number",
"col2" : "string",
"col3" : "string",
"col4" : "date"
},
"last_updated_by" : ObjectId("5dc0aed15399202590f34a54")
}
在“columnname_datatype”子文档中,其键 col1、col2 等可能会根据用户输入而有所不同(本质上是动态的)。
第二个集合 fieldlistvalues 带有以下示例文档:
{
"_id" : "test_data1",
"name" : "Test Data version 1",
"fieldlist_version" : ObjectId("5de3aafd2e46e531a45e441a"),
"last_updated_date" : ISODate("2014-10-11T18:59:06.313+05:30"),
"fieldlistarray" : [
{
"PKid" : "4902121027",
"first_release_value" : 2014.67,
"production_values" : [
73,
18309,
12636
],
"col1" : 13431.666666666666,
"real_time_data" : {
},
"col5" : null,
"status" : "ACTIVE",
"col2" : "JULESBURG",
"col3" : "EOG RES",
"col4" : "03/15/2015"
},
{
"PKid" : "4202121786",
"first_release_value" : 14.41667,
"olddata" : [
204.8333333333333,
2009.9166666666667
],
"production_values" : [
1945,
762,
315,
957
],
"col1" : 775.3333333333334,
"status" : "INACTIVE",
"col2" : "Not Available",
"col3" : "CIRQUE, LP",
"di_status" : "P & A",
"col4" : "12/15/2020"
},
"miscdata" : [
{
"method" : null,
"event_start_indices" : [
1,
10,
22
],
"types" : "misc",
"result" : 0
}
]
]
}
我正在寻找以下输出
{col1: [13431.666666666666, 775.3333333333334]},
{col2: ["JULESBURG", "Not Available"]},
{col3: ["EOG RES", "CIRQUE, LP"]},
{col4: [03/15/2015, 12/15/2020]}
尝试将 $lookup 与 let & 管道直接与数组一起使用(在本例中为 fieldlistarray[]),但没有得到想要的结果。
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework