When it comes to removing a family from the server/publication methods, I invoke a method by calling deletedFamily like so:
deletedFamily(family) {
if (Meteor.user().roles[0] == "admin") {
var myUsers = Meteor.users.find({"profile.family_id": family._id}).fetch();
for (var i = 0; i < myUsers.length; i++) {
UsersDeleted.insert(myUsers[i]);
Meteor.users.remove(myUsers[i]);
}
var myGuests= Guests.find({"profile.family_id": family._id}).fetch();
for (var i = 0; i < myGuests.length; i++) {
GuestsDeleted.insert(myGuests[i]);
Guests.remove(myGuests[i]);
}
FamiliesDeleted.insert(family);
Families.remove(family);
}
}
My aim is to handle exceptions and capture any errors that may occur. Although Meteor does not have built-in transactions, displaying the result of the process to the user in the front-end is essential.