I am trying to fetch users based on query, subscribe method returns user which is not part of publish. If my publish returning 5 users, on client subscribe returning 5+1 user. Along with the published users subscribe returning additional user, in this case the additional user is logged in user.
Please find my publish and subscribe methods below.
Publish Method.
Meteor.publish('allUsersPublish', function(){
var userInfo = Meteor.users.findOne({_id: this.userId});
var query = {};
if(this.userId){
if(userInfo.profile.isOrgAdmin){
query = {
"profile.orgId" : this.userId
}
}else{
query = {
"createdBy" : this.userId
}
}
}
return Meteor.users.find(query);
});
Subscribe method in router.
Router.route('/user',{
name : 'user.list',
layoutTemplate : 'layoutAfterAuth',
waitOn: function() {
return Meteor.subscribe('allUsersPublish');
},
data : function(){
return {
userListData : Meteor.users.find({} , { sort: {createdAt: -1}})
};
},
action : function (){
this.render('userListPage');
}
});