Mongo lookup 二级检索pipeline用法
{
"$lookup": {
"from": "siteTemplateExporting",
"let": {
"siteID": "$siteID"
},
"pipeline": [
{
"$match": {
"$expr": {
"$and": [
{
"$eq": [
"$templateID",
"$$templateID"
]
}
]
}
}
},
{
"$sort": {
"utime": -1,
"ctime": -1,
"_id": -1
}
}
],
'as': 'siteTemplateExportingArray'
}
}
两个表的关联是通过let
定义关联及其表达式,pipeline
为二级查询条件,其中必须由$expr
开头,中间可写$eq
,$gte
,$lte
等表达式