我正在创建具有聚合的mongodb,它应该在其中加入两个表,所以我使用了$ lookup,但查询返回了我一个空数组 这是我的查询
return userScoringModel.aggregate([
{
"$match": {
examId: new ObjectId(req.params.examId),
user_Id: new ObjectId(req.params.userId),
subject: subject,
correctMark: {$lt: 0}
}
},
{
$lookup: {
from: "examPortalQuestions",
localField: "questionId",
foreignField: "_id",
as: "question_text"
}
},
{
"$group": {
"_id": {chapter: '$chapter'},
"questionNumbers": {$push: "$questionNo"},
"question_text": {$push: '$question_text'}
}
},
{
"$project": {
"_id": 0,
"subject": {
"name": "$_id.subject",
"chapter": "$_id.chapter",
"questionNumber": "$questionNumbers",
"question": "$question_text"
}
}
}
]).exec()
这是输出
{
"subject": {
"chapter": "NUMBER TEST AND PAIR FINDING",
"questionNumber": [
"20"
],
"question": [
[]
]
}
},
样品采集 得分表:
_id, examid, userid , questionId, chapter
objectId ObjectId ObjectId ObjectId (ref:'questiontable') XYZ
objectId ObjectId ObjectId ObjectId (ref:'questiontable') qwe
问题表:
_id, question,
ObjectId what is abc?
我在这里问题数组为空 有人可以建议我如何将其存档 预先感谢