I have collection called Rooms, now, I want to publish different subsets of Room depending on where the user is on the app, so, this is what I had in mind:
Meteor.publish('roomList', function() {
return Rooms.find({}, {fields: {'roomId': 1, 'playerCount': 1, 'isPlaying': 1}});
});
Meteor.publish('roomInfo', function(_id) {
return Rooms.find({_id: _id}, {fields: {'players': 1}});
})
Meteor.publish('roomGame', function(_id) {
return Rooms.find({_id: _id}, {fields: {'game': 1}});
})
I don't want to throttle the connection sending players info when the user is just browsing rooms, however, when a user enters a room, I want to subscribe him to roomInfo so he can see who's in the room, and when the room is playing, subscribe to roomGame which contains game info. This is how I subscribe(at this point, user is already subscribed to roomList).
Router.route('/sala/:_id', {
name: 'roomLobby',
waitOn: function() {
return this.subscribe('roomInfo', this.params._id);
},
data:function(){
var r = Rooms.findOne(this.params._id);
console.log(r.players);
return r;
}
});
However, r.players always come up as undefined.
What am I missing?