对于那个mysql查询的mongoDB查询是怎么在mongoDB中使用join的,我面临的问题是在mysql中编写?
SELECT t.uid, count(j.job_id) AS x
FROM verify AS t
LEFT JOIN jobs AS j
ON t.uid = j.job_id
答案 0 :(得分:1)
如下所示,使用聚合框架$project
& $lookup
管道:
db.collection1.aggregation[{
$project: {
'uid': 1,
"x": {
"$size": "job_id"
}
},
$lookup: {
from: 'collection2',
localField: 'uid',
foreignField: 'job_id',
as: 'j'
}
}]