I’ve problems with understanding of Publish and Subscribe. I’ve the following collections on the server:
Persons --> male and female
Addresses --> Addresses of the Persons
‘Addresses’ Collection has in each item the _id of the ‘Persons’ item, like so:
The ‘Persons’ publish function look like so:
Meteor.publish(‘persons’, function() {return Persons.find({gender: ‘male’}); );
Now the question:
How should I wirte the Meteor.publish for the ‘Addresses’ Collection if I want to publish the Addresses according to “Persons.find({gender: ‘male’})”?
You may have simplified your example for your question, but I would first consider denormalising your collections. In other words, keep all data for a person (name and address) together in the same document in a single collection.
Notice that the above is not reactive, i.e. if a new male person is added to Persons, the corresponding address is not published. To see how to implement a reactive join, see here.
I guess @robfallows is right - it’s a mongo-way and its much better to fetch the data from single collection. I agree that working with nested properties is painfull but you could write a simple interface to deal with nested adddress on the client or server side