Meteor.call from autoValue in SimpleScema doubling

Hey all!

So I am trying to send a notification e-mail when a new field is inserted into a collection in order to alert the a user they have a class to schedule. Though the insert is only occurring 3 times, it is sending each email twice.

Below is my Scema code, how can I make sure this only sends once on initial insert?

notified:{
      //idealy we will store the id of the email sent that contains all the data.. including to see if that email was opened w/ a trcker
      type: String,
      autoValue: function(){
        if(this.isInsert && (!this.isSet || this.value.length === 0)){
           Meteor.call('sendEmail', toEmailVar, fromEmailVar , 'sub', 'msg', (err) =>{
              if(err)
                return "no";
            });
          return "yes";
        }
      }
    }

That’s really not the right place for that. Check out the official Meteor guide for information on hooks.

1 Like

I agree with @bmanturner that it’s not the right place to do that.

As for why it sends twice, there’s a few things that could be triggering this. If you’re inserting in an isomorphic method, it will run both on the client and server, both running the Meteor call.
Or if you’re using a validatedMethod, it will run the validation, triggering autovalue on both server and client.

1 Like