我需要您的帮助。 我有4个收藏集.. 国家:
{Country:[
{
"MENU": "CNTY",
"DESP": "India",
"CODE": "IND"
}]
}
状态:
{
State: [
{
"MENU": "STATE",
"CNTY": "IND",
"DESP": "Andhra Pradesh",
"CODE": "AP",
"TINCODE": "37"
}]
}
地区
{District:[
{
"CODE": "504",
"DESP": "KADAPA",
"STATE": "AP",
"CNTY": "IND"
}
]}
小镇
{Town:[{
"Menu": "TOWN",
"CODE": "AP03546",
"District": "504",
"DESP": "Abbavaram",
"Pincode": "516270"
}]
}
我已经尝试使用汇总和查找
DBclient.db("Dictionary").collection("Country").aggregate([{
$lookup: {
from: "State",
localField: "CNTY",
foreignField: "CODE",
as: "states"
}
}, {
$unwind: "$states"
},
{
$lookup: {
from: "Districts",
localField: "states.CODE",
foreignField: "STATE",
as: "district"
}
}, {
$unwind: "$district"
},
{
$lookup: {
from: "Towns",
localField: "district.CODE",
foreignField: "District",
as: "towns"
}
}, {
$unwind: "$towns"
}
]).toArray();
我得到了null
数组。这个查询有什么问题..plz给我建议。