Meteor publication: Hiding certain fields in an array document field?

不想你离开。 提交于 2019-12-12 04:48:58

问题


I have a collection with documents like this:

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

Is there a way to write a publication that hides a field in the family field array? So if I subscribed to the publication I would get:

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

回答1:


According to the Meteor docs, something like this could work:

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


来源:https://stackoverflow.com/questions/29793161/meteor-publication-hiding-certain-fields-in-an-array-document-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!