如何从 Meteor 发布中排除对象数组中的对象键

How to exclude object keys within arrays within objects from Meteor publication

我正在将一些数据发布到 Meteor blaze 模板,我想 return 特定字段,但它是一个嵌套 arrays/objects 的复杂对象,所以我不确定该怎么做

这是我要发布的对象的示例

{ "_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}});

我如何修改该出版物以排除我用箭头突出显示的键 "correct"?

问题数组 > 问题对象 > 答案数组 > 答案对象 > 正确键

如果您要发布所有内容,但想排除一个或多个字段(似乎是这样),这应该可行:

return Assessments.find( {"name": "Exam Name"}, {fields: {
    'questions.answers.correct': 0
}});