lookup联表查询,如何遍历数组,匹配对应的数据?
表1
"_id":"2a0398605f1114*****d69a167ebf9ed"
"name":"A_TL"
"alistArray":[100,101,200,201]
表二
"_id":"2a0398605f1114*****d69a167ebf9ed"
"alistID":"301"
"time":"20-10-10"
------------------------------------------------------
"_id":"2a0398605f1114*****d69a167ebf9ed"
"alistID":"100"
"time":"21-10-10"
------------------------------------------------------
"_id":"2a0398605f1114*****d69a167ebf9ed"
"alistID":"200"
"time":"20-12-10"
------------------------------------------------------
"_id":"2a0398605f1114*****d69a167ebf9ed"
"alistID":"201"
"time":"10-10-10"
------------------------------------------------------
"_id":"2a0398605f1114*****d69a167ebf9ed"
"alistID":"501"
"time":"25-10-10"
遍历【表1】里”alistArray“字段里的所有值,联表查询【表2】里的”alistID“相匹配的数据,
实现结果:
"_id":"2a0398605f1114*****d69a167ebf9ed"
"name":"A_TL"
"alistArray":[100,101,200,201]
"newlist":[
{
"_id":"2a0398605f1114*****d69a167ebf9ed"
"alistID":"100"
"time":"21-10-10"
},
{
"_id":"2a0398605f1114*****d69a167ebf9ed"
"alistID":"200"
"time":"20-12-10"
},
{
"_id":"2a0398605f1114*****d69a167ebf9ed"
"alistID":"201"
"time":"10-10-10"
}
]