问题描述
我有两个以上的表,并且已加入$ lookup,并且未使用其他表的引用
var gettopjobs = await jobs.aggregate([
{
$lookup:
{
"from":"tbldevprofiles","localField": "userid","foreignField": "userid","as":"devporfile"
}
},{$unwind: '$devporfile'},{
$lookup:
{
"from":"tblskils","localField": "skills","foreignField": "skillid","as":"jobskills"
}
},{
$lookup:
{
"from":"tbljobcomments","localField": "_id","foreignField": "jobid","as":"jobcmt"
},},{
$lookup:
{
"from":"tblusers","localField": "jobcmt.userid","foreignField": "_id","as":"jobcmtusers"
},{
$addFields: {
skills: {
$reduce: {
input: "$jobskills",initialValue: [],in: {
$concatArrays: [["$$this.name"],"$$value"]
}
}
}
}
},{
$project:{
skills:1,salary:1,jobtype:1,createdon:1,jobtitle:1,category:1,description:1,'devporfile.profileimg':1,'devporfile.location':1,jobcmt:1,jobcmtusers:1,}}
]);
我得到了这样的输出
{
"gettopjobs": [
{
"_id": "5f4fe3e39b647e3ee459b7be","skills": [
"Illustrator","Photoshop","wordpress","PHP"
],"salary": 100000,"jobtype": "Full Time","description": "Lorem ipsum dolor sit amet,consectetur adipiscing elit. Aliquam luctus hendrerit metus,ut ullamcorper quam finibus at. Lorem ipsum dolor sit amet,ut ullamcorper quam finibus at.","createdon": "2020-09-02T18:25:50.249Z","jobtitle": "Mvc C#","category": "Developer","devporfile": {
"location": "london","profileimg": "15984497234434387.jpg"
},"jobcmt": [
{
"_id": "5f51d668dd259928f06c0e23","jobid": "5f4fe3e39b647e3ee459b7be","userid": "5f41115fbd904134883ae2d8","comment": "Lorem ipsum dolor sit amet,"createdon": "2020-09-04T05:53:44.917Z","__v": 0
},{
"_id": "5f51d6e16e32973db09229d4","comment": "testestsetsert","createdon": "2020-09-04T05:55:45.895Z",{
"_id": "5f51d776d6698625e4471810","comment": "testsetsetset","createdon": "2020-09-04T05:58:14.066Z",{
"_id": "5f51d82aae53020354359b41","createdon": "2020-09-04T06:01:14.510Z",{
"_id": "5f51e72813bdb91294a631d6","userid": "5f411181bd904134883ae2da","__v": 0
}
],"jobcmtusers": [
{
"_id": "5f41115fbd904134883ae2d8","companyid": [
"5f411160bd904134883ae2d9"
],"email": "sss@abc.com","password": "$2b$10$gKIK.e3zuA02lSheRZ9vduck.6M9kif1FwZuuLDC4OlzmfH1x3GU6","phonenumber": "777777777","fullname": "abc","Country": "India","createddate": "2020-08-22T12:36:47.856Z","modifieddate": "2020-08-22T12:36:47.856Z","usertype": 1,"isactive": 1,"__v": 1
},{
"_id": "5f411181bd904134883ae2da","companyid": [],"email": "abc@gmail.com","password": "$2b$10$nQMdC.NPSe1kw857RA9GneahgC.QZt358IY6In.W/FLfL3jvX5f/a","phonenumber": "7777777777","fullname": "ppp","createddate": "2020-08-22T12:37:21.082Z","modifieddate": "2020-08-22T12:37:21.082Z","usertype": 2,"__v": 0
}
]
}
]
}
我要根据用户ID
在 jobcmt 中找到 jobcmtusers 详细信息那么我们如何在单个查询中做到这一点
我要根据用户ID
在 jobcmt 中找到 jobcmtusers 详细信息那么我们如何在单个查询中做到这一点
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)