In my social application (like FB, for example), I have a strange need to combine two cursors of the same collection users in one edition!
The Meteor server will print this error: "The publish function returns multiple cursors for users in the collection."
Perhaps this is not possible to do in Meteor 0.7.2, maybe I'm wrong. But I saw that the cursor structure is pretty simple, since I can make a simple merge of the array and return the cursor back?
CUSTOMER
Meteor.subscribe('friendById', friend._id, function() {
});
SERVER
getUsersByIds = function(usersIds) {
return Meteor.users.find({_id: {$in: usersIds} },
{
fields: {
username: 1,
avatar_url: 1
}
});
};
getFriendById = function(userId) {
return Meteor.users.find(userId,
{
fields: {
username: 1,
avatar_url: 1,
online: 1,
favorites: 1,
follow: 1,
friends: 1
}
});
};
Meteor.publish('friendById', function(userId) {
if(this.userId && userId)
{
var userCur = getFriendById(userId),
userFriends = userCur.fetch()[0].friends,
retCurs = [];
retCurs.push( userCur );
if(userFriends.length > 0)
retCurs.push( getUsersByIds(userFriends) );
return retCurs;
}
else
this.ready();
});
source
share