Meteor template helper to check if a document exists


#1

I want to register a helper that i can use in the templates to check if a document exists.

I check if a document exists like this

    var selector = {
    userid: "3R2pKdT3x9PjWLsD8",
    };;
            
   var this_exists = Af.find(selector, {limit: 1}).count() > 0;

I am trying to register a helper like this

Template.registerHelper('ex', function() {
    var selector = {
    userid: "3R2pKdT3x9PjWLsD8",
    };

            
     var this_exists = Af.find(selector, {limit: 1}).count() > 0;

    if(this_exists == true){
         return true;
     }
     else{
        return false;
     }
});

and use it like this in my tempates

{{#if ex}}
                {{> quickForm collection="Af" doc=cdoc id="updateSettings" omitFields="userid"
                class="settings" type="update" buttonContent="Update Settings"}}

                {{else}}

                 {{> quickForm collection="Af" doc=this id="updateSettings" omitFields="userid"
                class="settings" type="insert" buttonContent="Insert Settings"}}

                {{/if}}

but this does not work. Where am i going wrong?.