如何从Meteor出版物中排除对象内数组内的对象键

时间:2016-10-24 14:26:38

标签: arrays mongodb meteor meteor-publications

我正在向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;正确的密钥

1 个答案:

答案 0 :(得分:1)

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

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