Meteor - 从用户列表中删除当前用户

时间:2016-01-28 02:27:31

标签: meteor

我目前正在发布群组中的用户列表。虽然这有效,但我无法阻止当前用户出现在列表中。如何删除当前用户。提前感谢任何建议和帮助。

路径:publish.js

Meteor.publish('studentList', function (group) {
  if (Roles.userIsInRole(this.userId, ['teacher'], group)) {

  return Meteor.users.find({roles:'student'}, {fields:{emails:1, profile: 1, roles: 1}});

  } else {

    // user not authorized. do not publish secrets
    this.stop();
    return;

  }
});

路径:studentList.js

Template.studentList.onCreated(function() {
    var self = this;
    self.autorun(function() {
        self.subscribe('studentList')
    });
});

Template.studentList.helpers({
    studentList: ()=> { 
        return Meteor.users.find({}); 
    },
});

2 个答案:

答案 0 :(得分:3)

在您的客户端代码中,您可以排除用户ID与当前用户匹配的用户:

Template.studentList.helpers({
    studentList: ()=> { 
        return Meteor.users.find({_id: { $ne: Meteor.userId() }}); 
    },
});

或者您可以通过执行Meteor.users.find({})。fetch()。someRemoveLogic()来从客户端的结果中删除它。

答案 1 :(得分:3)

默认情况下,登录用户的数据会订阅到客户端。没有办法删除该订阅。因为引擎盖下Meteor.user()起作用。如果您需要将其从客户端帮助程序中排除,则可以进行排除当前用户数据的查询。一个例子就是这个

Meteor.users.find({_id: { $ne: Meteor.userId()}}); 
相关问题