javascript - 如何在猫鼬中加入和运行 NOT EXISTS 查询
问题描述
我有一个 sql 查询,我需要在 mongoose 聚合中进行转换
SQL:
Select a.participant_id, a.name
from participant a , settlementAccount b
Where a.settlementAccount = b.id
and b.account_type = "FundingAgent"
and Not Exists
(select 1 from settlementAccount c where b.account_type = "Tracking" and a.id = c.owner_id)
我试图聚合猫鼬,但停留在Not Exists
查询的一部分。
猫鼬:
Participant.aggregate([{
$lookup: {
from: 'settlementAccount', // collection name in db
localField: 'settlementAccount',
foreignField: 'id',
as: 'settlementOwners'
}
},
{
$match:
{
$and:
[
{'settlementOwners.account_type': 'FundingAgent'},
{'settlementOwners.account_type': {$ne: 'Tracking'}},
{'id': {$ne: 'settlementOwners.owner_id'}}
]
}
},
{$project: {_id: '$_id', id: '$id', name: '$name'}}
])
我不知道这是否是正确的实现。有谁知道如何将这些查询组合在一起?
解决方案
推荐阅读
- typescript - 在 CDK 中将 AWS Step Functions 与 API Gateway 集成时遇到问题
- c++ - 如何找到 Visual Studio 正在调用的确切编译器可执行文件?
- apache-nifi - 无法导入在 Git 存储库中提交的 Nifi Registry 流
- python - ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。收到的完整形状:[8, 28, 28]
- docker - 如何在本地构建和运行 Druid
- node.js - 使用 electron 或 node.js 将文件存储在本地驱动器文件夹中
- python - 如何在 syslog.gz 中删除,同时使用 grep 查找行?- Linux
- python - 在 scikit-learn 中使用 DecisionTreeClassifier 修复 100% 准确率
- reactjs - 从哪里导入 Firebase 存储项目的类型参考 - React Typescript?
- c# - POST 数据空模型