流星出版物:隐藏数组文档字段中的某些字段?

时间:2015-04-22 09:26:13

标签: mongodb meteor publish-subscribe

我有一个包含这样文件的集合:

{
    _id: af3F3afafaa,
    firstName: "John",
    family: [{name: "David", relation: "brother", alive: true},
             {name: "Susan", relation: "mother", alive: false}]
}

有没有办法编写隐藏字段数组中字段的出版物?所以,如果我订阅了该出版物,我会得到:

    {
    _id: af3F3afafaa,
    firstName: "John",
    family: [{name: "David", alive: true},
             {name: "Susan", alive: false"}]
    }

1 个答案:

答案 0 :(得分:0)

根据Meteor docs,这样的事情可以起作用:

Meteor.publish('family', function(famId) {
  return Families.find(famId, {
    fields : {
      "family.relation" : 0 //Exclude family.relation from the sent data
    }
  });
});