我正在向Meteor blaze模板发布一些数据,我想返回特定字段,但它是一个带有嵌套数组/对象的复杂对象,所以我不知道该怎么做
以下是我发布的对象的示例
{
"_id": "q9i6qAZmKcf6MCPE2",
"name": "Exam Name",
"questions": [
{
"number": 1,
"question": "Question 1",
"multipleTrue": false,
"answers": [
{
"letter": "a",
"answer": "Blah Blah",
"correct": false <--------------
},
{
"letter": "b",
"answer": "Blah Blah",
"correct": true <--------------
}
]
},
{
"number": 2,
"question": "Question 2",
"multipleTrue": false,
"answers": [
{
"letter": "a",
"answer": "Blah Blah",
"correct": true <--------------
},
{
"letter": "b",
"answer": "Blah Blah",
"correct": true <--------------
}
]
}
]
}
我将使用以下代码发布此内容:
return Assessments.find( {"name": "Exam Name"}, {fields: {name: 1, questions: 1}});
如何修改该出版物以排除我用箭头突出显示的“正确”键?
问题数组&gt;问题对象&gt;答案数组&gt;答案对象&gt;正确的密钥
答案 0 :(得分:1)
如果您要发布所有内容,但想要排除一个或多个字段(看起来像这样),这应该可行:
return Assessments.find( {"name": "Exam Name"}, {fields: {
'questions.answers.correct': 0
}});