Collection hooks if failed

Hello ,
I am using collection hooks … Everything is going fine but i was wondering what i can do with the following case :

I have employee collection using the quick-form , after i submit the form, i use the collection hook ‘after.insert’ to create user account with 'Accounts.createUser ’ method … my question is what about if the collection hooks failed to create account ( ie : the email address has been used before or what ever ) , is it gonna revert the previous insertion of the employee record, if not … then i think this a big problem … your advice guys

Try this. you can use option callback to check if it error or not. if it error just remove current Employee doc.
http://docs.meteor.com/#/full/accounts_passwords

Employee.after.insert((userId, doc)=>{
 Accounts.createUser({
      username: 'user',
      email: 'user@example.com',
    }, function(err){
   if(err){
    Employee.remove(doc._id)
   }
 })
})

Thank you
got it :slight_smile:
cheers