I have two Collections in Meteor, and trying to join them. As defined in collections/collections.js
Producers = new Mongo.Collection('producers');
Projects = new Mongo.Collection('projects');
Conceptually, one Producer has 0 to many Projects. One Project must have a Producer. So, a ProducerID field is in each Project document (row) in Mongo. I seeded the Mongo database with data.
When my template for viewing Projects is displayed, I want it to have access to the Producer's attributes.
In Iron Router's config (in /app.js), I have
Router.route('project', {
path: '/project/:name',
template: 'project',
waitOn: function() {
return Meteor.subscribe('ProjectInfo', this.params.name);
},
data: function() {
return Projects.find();
}
});
I have two publishes on the server (in /server/publish.js):
Meteor.publish("ProjectInfo", function(projectName) {
return Projects.find( {name: projectName} );
});
Meteor.publish("ProducerInfo", function(producerid) {
return Producers.find( {_id: producerid});
});
Question 1: How to join? I definitely don't want to just throw Producer data into each Project, because it makes it harder to update the database when a Producer data changes.
Question 2: Why does Iron Router need a "data:" field, when it already has a Subscribe in the waitOn?
data: function() {
return Projects.find();
}
Thanks in advance.