mongodb - 使用查找、匹配的 mongodb 聚合查询
问题描述
我尝试编写一个查询,其中集合 1(用户)由用户名、报告经理、empId 和集合 2(报价集合)组成我想要的结果是,如果亲自登录,经理需要显示由团队和报价创建的报价自己创造的
User.aggregate([
{ $match: { reportingManager: req.user.user.name } },
{
$lookup:
{
from: 'Quotation',
localField: 'empId',
foreignField: 'salesCrm',
as: 'data'
}
},
{ $unwind: "$data" },
{$match:{"data.salesCrm":{$in:[req.user.user.empId]}}}
]
我的用户收藏
{
"_id" : ObjectId("5b569cb4e924600e208660d6"),
"name" : "abc",
"email" : "abc@knowledgew.com",
"designation" : "Software Developer",
"department" : "Software Developer",
"empId" : "123",
"mobileNo" : 24564121654.0,
"password" : "$2a$10$5d/0XV.yq.w5.Ipwc2uvtuvK4Mxji0f1mUW8rBwlhu/QR8jpztoOu",
"vertical" : "Education,Market Research,Manufacturing,IT/ITES,BFSI",
"reportingManager" : "def",
"level" : "L1"
}
我的报价集
{
"_id" : ObjectId("5b4f27f476d65f25cc8d80ba"),
"clientId" : "VPKW00001",
"clientName" : "sssssss",
"quotationId" : "00001_1819_CG7JE",
"pmCost" : NumberInt(34),
"contactPerson" : "5b4310db728ebf030c447ebd",
"fileDomain" : "Panel Interview",
"clientDomain" : "Software",
"fuzzyMatch" : "No",
"fileEngineering" : NumberInt(34),
"workingDays" : "34",
"currency" : "GBP",
"scopeOfWork" : "LZ6PKLY_prod2.png",
"projectPlan" : "V1RK7BW_prod2.png",
"projectType" : "nnnn",
"projectValue" : 646.41,
"salesCrm" : "123",
}
解决方案
推荐阅读
- c - 当我们将 char * 转换为 int * 时,后台或内存中会发生什么
- javascript - 如何在 nodejs 后端使用 Dropbox API v2 上传图片
- swift - `return nil` 和 `return` 可以互换吗?
- angular - ngIf 的行为和 Angular 中的属性绑定
- c# - 如何在 C# 中模拟快捷方式?
- r - 在 mutate 中使用引号:mutate_(.dots = ...) 的替代方法
- java - 假的 RestTemplate ajax 端点上有 77 个卡住的线程
- javascript - 检查 Router-flux 中的作用
- python - 在 Outlook for Python 脚本中选择多个邮件
- node.js - Socket.io | 类型错误:socket.emit 不是函数