【发布时间】:2018-02-15 20:04:15
【问题描述】:
我有一个作业架构和一个应用程序架构。应用程序架构已嵌入作业架构中。这就像申请此特定工作的候选人
{
"_id" : ObjectId("5a745a49e4a4d9203cf506ed"),
"active" : true,
"applications" : [
{
"applied" : true,
"shortlisted" : true,
"interviewed" : false,
"offered" : false,
"hired" : false,
"rejected" : false,
"candId":1
},
{
"applied" : true,
"shortlisted" : false,
"interviewed" : false,
"offered" : false,
"hired" : false,
"rejected" : false,
"candId":2
},
{
"applied" : true,
"shortlisted" : false,
"interviewed" : false,
"offered" : false,
"hired" : false,
"rejected" : false,
"candId":3
},
{
"applied" : true,
"shortlisted" : false,
"interviewed" : false,
"offered" : false,
"hired" : false,
"rejected" : false,
"candId":4
}
],
"job_title" : "MERN Stack developer",
"job_description" : "<p>If more than one component needs to make use of this, we have to either duplicate the function, or extract it into a shared helper and import it in multiple places - both are less than ideal.</p><p>Vuex allows us to define \"getters\" in the store. You can think of them as computed properties for stores. Like computed properties, a getter's result is cached based on its dependencies, and will only re-evaluate when some of its dependencies have changed.</p><p>Getters will receive the state as their 1st argument:</p>",
"max_experience" : 3,
"max_salary" : 4,
"min_experience" : 2,
"min_salary" : 3
}
在我的申请中,我有候选人经历的阶段(申请、入围、面试、提供...)
所以我想写一个查询,它会在应用阶段给我一个结果
{
"applied" : true,
"shortlisted" : false,
"interviewed" : false,
"offered" : false,
"hired" : false,
"rejected" : false,
"candId":2
},
{
"applied" : true,
"shortlisted" : false,
"interviewed" : false,
"offered" : false,
"hired" : false,
"rejected" : false,
"candId":3
},
{
"applied" : true,
"shortlisted" : false,
"interviewed" : false,
"offered" : false,
"hired" : false,
"rejected" : false,
"candId":4
}
基本上只有applyed应该设置为true,其他设置为false
并在入围阶段
{
"applied" : true,
"shortlisted" : true,
"interviewed" : false,
"offered" : false,
"hired" : false,
"rejected" : false,
"candId":1
}
有工作或无工作的查询结果无所谓
编辑
Job.find({
_id : req.params.id,
'applications.applied': req.body.applied,
'applications.shortlisted' : req.body.shortlisted,
'applications.interviewed' : req.body.interviewed,
'applications.offered' : req.body.offered,
'applications.hired' : req.body.hired,
'applications.rejected' : req.body.rejected
}).populate('applications.talentId').then((job, err) => {
if(err){
return res.status(500).send({error: "There was some error"})
}
res.status(200).json(job)
})
我正在获取每个阶段的所有应用程序的整个作业对象
【问题讨论】:
标签: mongodb mongoose mongodb-query