问题
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