Let's say that I have two Meteor collections: "Stations" and "Songs". Each song has a foreign key to a station to show that it was played on that station.
Now I want to publish the last 3 played songs of every station like so:
Meteor.publish("all-last-three-songs", function () {
var stations = Stations.find();
var stationIDs = stations.map(function(station) { return station._id });
var songs = Songs.find({station_id: {$in: stationIDs}}, {sort: {time: -1}, {limit: 3}});
return songs;
});
That publishes only 3 songs for all stations of course. How can I achieve that a cursor for the last 3 songs for every station gets returned? I don't want to do the filtering on the client side.
Thank you! :)