Search code examples
meteormeteor-accounts

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


I have a field in the Meteor.users collection that can be set to true or false. I want to check if the field for the current user is equal to true or false.

How would this be done?


Solution

  • inside a template

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

    inside a publish function

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

    anywhere else

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

    Note: If your custom field isn't visible on the client, please see this question.