In my meteor app I'm implementing functionality to send messages between users. In my app I have a route and template that displays all messages sent to the user.
The controller code:
this.UserMessagesController = RouteController.extend({
template: "UserMessages",
waitOn: function() {
return Meteor.subscribe("userMessages");
},
data: function() {
return {
"messages": UserMessages.find({to: Meteor.userId()}, {sort: {time: -1}} )
}
}
});
}
});
On the server side I have a publish functions
Meteor.publish("userMessages", function() {
var userId = this.userId;
return UserMessages.find({to: userId}, {});
});
Also I have a global subscription to unread messages:
Deps.autorun(function() {
if (Meteor.user()) {
Meteor.subscribe("unreadMessages");
}
});
Meteor.publish("unreadMessages", function() {
return UserMessages.find({to: this.userId, read: undefined}, {});
});
The problem is: I can see only unread messages rendered on template (and unread message only in client minimongo collection as well)
But if I remove filter {to: userId} from publish function or remove subscription to unread messages I can perfectly see each message!
PS: I tried to debug publish function setting breakpoint and evaluating UserMessages.find({to: userId}, {}).fetch() and I got absolutely correct array consisting of 15 messages.
PPS: I got no error messages on the server side as well as on client side
What might be a problem?