检查 Meteor.users 集合中的字段是否为真/假?

Check if a field in Meteor.users collection is true / false?

我在 Meteor.users 集合中有一个字段可以设置为 truefalse。我想检查当前用户的字段是否等于 truefalse.

如何做到这一点?

在模板中

{{#if currentUser.isAwesome}}
  <p>You are awesome!</p>
{{/if}}

在发布函数中

Meteor.publish('something', function() {
  var user = Meteor.users.findOne(this.userId);
  if (user.isAwesome)
    console.log('You are awesome!');
});

其他地方

if(Meteor.user().isAwesome)
  console.log('You are awesome!');

注意:如果您的自定义字段在客户端上不可见,请参阅