Question.findOne({"choices._id": choiceId})
.select('choices')
但是它返回了我在数组中具有该ID的问题,以及其他选择。例如,我正在寻找ID为5f7f05f8aec5103db6c15534的选择,但它返回所有选择:
{
"_id": "5f7f05f8aec5103db6c15532",
"choices": [
{
"isCorrect": false,
"_id": "5f7f05f8aec5103db6c15534",
"content": "pe asta"
},
{
"isCorrect": true,
"_id": "5f7f05f8aec5103db6c15533",
"content": "pe asta update 2"
}
]
}
是否有可能在具有该ID的数组中返回ONLY对象?
答案 0 :(得分:0)
您可以尝试一下
Question.findOne({ 'choices._id': { $elemMatch: { _id: choiceId } } }, function (err, question) {
// your code goes here
});