如何在外键字段上使用通配符执行$查找?
任务是检索Keyword集合中desc子字符串为not的Transaction中的所有记录.
desc in交易可以采用ABC<;关键字&>定义的形式,并交叉引用到Keyword集合,如果找到,这应该是匹配的.
我想使用正则表达式.*XXX.*
的负匹配来完成任务.
不确定如何在$查找中放置正则表达式子句.
Transaction个Collection :
transactions=[
{
"_id": {
"$oid": "6480267ab9fe78e82131b737"
},
"date": {
"$date": "2020-06-22T00:00:00.000Z"
},
"desc": "abcKey1def",
},
{
"_id": {
"$oid": "6480267ab9fe78e82131b738"
},
"date": {
"$date": "2020-06-23T00:00:00.000Z"
},
"desc": "abcdef",
}
]
Keyword个Collection :
keyword=[
{
"_id": {
"$oid": "64816f3828372d84a93cd4ad"
},
"code": 123,
"desc": "Key1"
},
{
"_id": {
"$oid": "648174bf28372d84a93cd4b5"
},
"code": 456,
"desc": "Key2",
}
]
我知道我可能需要用let和pipeline...但不确定如何将它们组合在一起.
$lookup:{
from: "keyword",
let: {
desc:'$desc'
},
pipeline: [
....?
]
as: "result"
}